Activating a Specific UCS

Discussion in 'AutoCAD' started by mnash, Jan 10, 2005.

  1. mnash

    mnash Guest

    In any given drawing there is a UCS with a specific name to the UCS, in every drawing the name always consists of two parts, the first being the "filename in its entirety", followed by "-C".

    Example
    Drawing with filename "Section" will have a UCS in the drawing called "Section-C".
    Drawing with filename "Detail" will have a UCS in the drawing called "Detail-C".

    Is there a way where in all drawings we can activate the "filename+-C" UCS in all drawings?
    Thanks and cheers
    MN
     
    mnash, Jan 10, 2005
    #1
  2. mnash

    Matt W Guest

    Try this...

    Code:
    ; FROM ACADX.COM
    ;;;==================================================================
    ;;; (JustStem cFileName)
    ;;;  Returns the stem name (the file name before the extension)
    ;;;  from a complete path and file name.
    ;;;------------------------------------------------------------------
    ;;; Parameters:
    ;;;  cFileName  str to check
    ;;;------------------------------------------------------------------
    ;;; Returns:
    ;;;  [STR]
    ;;;  Example:  (setq a "C:\\MyFolder\\MyFile.txt")
    ;;;     (JustStem a) ; returns "MyFile"
    ;;;------------------------------------------------------------------
    (defun JustStem (cFileName / fName DotLoc)
    (setq fName (justFName cFileName))
    (setq DotLoc (rat "." fName))
    (if (> DotLoc 0)
    (substr fName 1 (1- DotLoc))
    fName
    ) ;_ end of if
    ) ;_ end of defun
    
    ; ALSO FROM ACADX.COM
    ;;;===========================================================================
    ;;; (Rat cSearchExpression cExpressionSearched)
    ;;;  Returns the numeric position of the last (rightmost)
    ;;;  occurrence of a character string within another character string.
    ;;;---------------------------------------------------------------------------
    ;;; Parameters:
    ;;;  cSearchExpression [STR] - String to search for
    ;;;  cExpressionSearched [STR] - String to search
    ;;;---------------------------------------------------------------------------
    ;;; Returns:
    ;;;  [INT] - Posistion of the string
    ;;;  Example:  (setq a "A Lot of Text.")
    ;;;     (Rat "Text" a) ; returns 10
    ;;;===========================================================================
    (defun Rat (cSearch cSearchIn / return SearchFor cont n)
    ;; We need to escape for special characters
    (cond
    (
    (= cSearch "\\")
    (setq SearchFor "*`\\*")
    )
    (
    (= cSearch ".")
    (setq SearchFor "*`.*")
    )
    (
    (= cSearch "#")
    (setq SearchFor "*`#*")
    )
    (
    (= cSearch "*")
    (setq SearchFor "*`**")
    )
    (
    (= cSearch "~")
    (setq SearchFor "*`~*")
    )
    (
    (= cSearch "-")
    (setq SearchFor "*`-*")
    )
    (
    (= cSearch ",")
    (setq SearchFor "*`,*")
    )
    (
    (= cSearch "`")
    (setq SearchFor "*``*")
    )
    (
    T
    (setq SearchFor (strcat "*" cSearch "*"))
    )
    ) ;_ end of cond
    
    (cond
    (
    ;; Make sure there is a match
    (not (wcmatch cSearchIn SearchFor))
    (setq return 0)
    )
    (
    T
    (setq n (strlen cSearchIn))
    (setq TestStr (substr cSearchIn n))
    (setq cont T)
    (while Cont
    (if (wcmatch TestStr SearchFor)
    (progn
    (setq Cont nil)
    (setq return n)
    ) ;_ end of progn
    (progn
    (setq n (1- n))
    (setq TestStr (substr cSearchIn n))
    
    ) ;_ end of progn
    ) ;_ end of if
    ) ;_ end of while
    )
    ) ;_ end of cond
    return
    ) ;_ end of defun
    
    (DEFUN C:UCS-TEST ( / )
    (COMMAND "UCS" "R" (STRCAT (JUSTSTEM (GETVAR "DWGNAME")) "-C"))
    )
    
    (PRINC)
    
     
    Matt W, Jan 10, 2005
    #2
  3. mnash

    mnash Guest

    Thanks Red Sock, but it don'e seem to work I'm getting a malformed error on input, and i[m way in over my head with this program. I thought it would be much simpler than this, guess I'm wrong
     
    mnash, Jan 10, 2005
    #3
  4. mnash

    ECCAD Guest

    Matt,
    You may have to attach a .zip with the code. When I cut/paste
    from Internet Explorer to Notepad / Wordpad, code that is in
    a 'box' like yours, I get (1) long sentence, no Cr/Lf - I have to
    go into the string and supply these manually in order to get
    the code readable..Just a thought.

    Bob
     
    ECCAD, Jan 10, 2005
    #4
  5. mnash

    T.Willey Guest

    To get the drawing name use
    (setq FileName (getvar "dwgname"))
    Then to get the base file name (with the extension) use
    (setq DwgName (vl-filename-base FileName))
    Then to get the UCS name use
    (setq UCSName (strcat DwgName "-C"))
    Then to restore the name use
    (command "_.ucs" "_r" UCSName)

    Hope that helps.
    Tim
     
    T.Willey, Jan 10, 2005
    #5
  6. mnash

    mnash Guest

    Thanks so much guys, but the ".dwg" is still being used in the filename, is it possible to filter out the ".dwg" for the UCS name?
    Happy New Year all
     
    mnash, Jan 11, 2005
    #6
  7. mnash

    Matt W Guest

    Huh.... never knew that was an issue. I always use OE and it's never been a
    problem for me.
    I'll keep that in mind.
    Thanks for the info.
     
    Matt W, Jan 11, 2005
    #7
  8. mnash

    T.Willey Guest

    (setq DwgName (vl-filename-base FileName))
    This should give you the base name for whatever FileName is.
    If FileName = "section.dwg", it should return just "section", but if that isn't working, then you could do something like
    (setq DwgName (substr 1 (- (strlen FileName) 4)))
    This will return everything but the last four items in the string.

    Hope that helped.
    Tim
     
    T.Willey, Jan 11, 2005
    #8
  9. mnash

    mnash Guest

    Tim both worked, I hav e afile with a bunch of small lisps and after eliminating all of the above lisp, I still got the malformed list error, so now I have to trouble shoot the rest of the lisp file, but thanks for the valuable knowledge.
     
    mnash, Jan 11, 2005
    #9
  10. mnash

    T.Willey Guest

    Happy to help.
    Hope you get your file in order.

    Tim
     
    T.Willey, Jan 11, 2005
    #10
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.