Jump to content

Recommended Posts

Posted

Can anybody tell me why when I have this line of code in my lisp I get nil for sfv?

 

(setq sfv (getvar 'ucsname))

 

Thanks for your help.

  • Replies 21
  • Created
  • Last Reply

Top Posters In This Topic

  • KRBeckman

    12

  • Lee Mac

    7

  • fixo

    1

  • BIGAL

    1

Top Posters In This Topic

Posted
Can anybody tell me why when I have this line of code in my lisp I get nil for sfv?

 

(setq sfv (getvar 'ucsname))

 

Thanks for your help.

 

See Help:

 

UCSNAME

 

(Read-only) Type:

String

Saved in Drawing

Stores the name of the current coordinate system for the current viewport in the current space.

Returns a null string if the current UCS is unnamed.

 

~'J'~

Posted

Thanks for your quick reply. Yeah I get that... when I copy and paste that line of code into the command line in autocad it comes up "*Front*", like its supposed to... Its only when it's ran within a lisp that I get nil.

Posted

Same result. I get "" for the variable.... Sorry if it caused some confusion, but earlier I said I was getting nil, when I'm actually getting "". Not sure if it makes a difference.

Posted

did you create a name for your ucs?

Posted

Yeah, I've tried to use the autocad "standard" named ucs "*FRONT*" and I've tried to re-save it as a new name, same result.

Posted

UCSNAME will return "" if the UCS is World, or unnamed, also bear in mind that UCSNAME will return the name of the current UCS being used. All seems to work fine for me.

Posted

This is weird, if I run the line of code within a lisp I get "", however if I copy/paste it into the command line i get "*FRONT*". I don't get it.

Posted

What LISP are you using? Both at the command-line and in the console return *FRONT* when I am in the Front UCS.

Posted
(setq sfv (getvar 'ucsname))

Posted

Oh right - I thought perhaps it was within another program.

 

Well, I can't explain it - as I say, the UCSNAME = "" is either World, or an unnamed UCS. Are you sure you are not perhaps getting confused with Views?

Posted

yeah, cause when I double click into the viewport I'm trying to extract the usc name from and type (getvar 'uscname) in the command line I get "*FRONT*". No worries Lee, thanks for trying. Can someone try this in AutoCAD 2008 and see if maybe its an issue with this version?

Posted
yeah, cause when I double click into the viewport I'm trying to extract the usc name from and type (getvar 'uscname) in the command line I get "*FRONT*".

 

So it works? Bear in mind that you can have different UCS's for ModelSpace and through a viewport in PaperSpace.

Posted

yeah, it works when typed in manually/copy pasted into the command line. However it doesn't work when ran within a lisp

Posted
yeah, it works when typed in manually/copy pasted into the command line. However it doesn't work when ran within a lisp

 

So, if I'm correct, you say that if you type:

 

(getvar 'ucsname)

At the command line you get "*FRONT*"

 

But when running a function:

 

(defun getucs nil
 (getvar 'ucsname))

You get "" ? Am I correct?

 

Just that there is no difference between running a LISP and entering the LISP code manually at the command line.

 

Lee

Posted
So, if I'm correct, you say that if you type:

 

(getvar 'ucsname)

At the command line you get "*FRONT*"

 

But when running a function:

 

(defun getucs nil
 (getvar 'ucsname))

You get "" ? Am I correct?

 

 

Yep, that's what's happening.

 

 

Just that there is no difference between running a LISP and entering the LISP code manually at the command line.

 

Lee

 

I know, that's what I'm saying, doesn't make any sence.

Posted

Lee, maybe you'll have a better solution for what I'm trying to accomplish...

 

Most of the time the objects I draw in modelspace are wider than they are deep, when looking down from the top view, however there are some that are deeper than wide. In this situation I'd like to make the object better fit the viewports (and the page) by twisting the top view 90°, rotating my front view so that it becomes the left view, and rotating my right view so that it becomes the front view. (Basically the same as rotating the objects in modelspace 90°, which would be alot easier, however my employer won't let me do that becuase it causes issues with the customer inserting our symbols into thier drawings)

 

Here's what I've got so far:

 

(defun c:rt ()

 (setvar 'tilemode 0)
 (command "_.zoom" "_w" '(-0.5 -0.5 0.0) '(11.0 8.5 0.0))
 (command "_.mspace")
 (setvar 'cvport 2)
 (setq tvt (* (/ (+ (getvar 'viewtwist) (/ pi 2)) pi) 180))
 (command "_.dview" "" "_twist" tvt "")
 (command "_.zoom" "_e")
 (setvar 'cvport 5)
 (setq sfv (getvar 'ucsname))
 (setq efv (cond ( (= sfv "*Front*") "_Left")
   ( (= sfv "*Left*") "_Back")
   ( (= sfv "*Back*") "_Right")
   ( (= sfv "*Right*") "_Front")))
 (command "_.-view" efv)
 (command "_.zoom" "_e")
 (setvar 'cvport 4)
 (setq srv (getvar 'ucsname))
 (setq erv (cond ( (= sfv "*Front*") "_Left")
   ( (= sfv "*Left*") "_Back")
   ( (= sfv "*Back*") "_Right")
   ( (= sfv "*Right*") "_Front")))
 (command "_.-view" erv)
 (command "_.zoom" "_e")
 (command "_.pspace")
 (princ)
 (princ "\nAll modelspace items rotated 90° about the top plane")
 (princ))

 

If there's a better way to do this I'm all ears.

Posted

I cannot quite get this to work, but maybe something along these lines if I have not misunderstood the intention. Perhaps others can correct it :)

 

(defun c:rt  (/ *error* Cross OBJLST OTL SS)
 (vl-load-com)

 (defun *error* (msg)
   (and otl (setvar 'TILEMODE otl))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ))

 ;; Vector Cross Product
 ;; Args: a,b Vectors
 
 (defun cross (a b)
   (list (- (* (cadr a) (caddr b))
            (* (cadr b) (caddr a)))
         (- (* (car b)  (caddr a))
            (* (car a)  (caddr b)))
         (- (* (car a)  (cadr b))
            (* (car b)  (cadr a)))))

 

 (setq otl (getvar 'TILEMODE))
 (setvar 'tilemode 0)

 (if (ssget "_X" (list '(0 . "VIEWPORT") (cons 410 (getvar 'CTAB))))
   (progn
     (vlax-for obj (setq ss (vla-get-activeSelectionSet
                              (vla-get-ActiveDocument (vlax-get-acad-object))))

       (setq ObjLst (cons obj ObjLst)))      
     (vla-delete ss)

     (mapcar
       (function
         (lambda (x)
           (vlax-put-property x 'TwistAngle
             (+ (vlax-get-property x 'TwistAngle) (/ pi 2.))) 

           (vlax-put-property x 'Direction
             (vlax-3D-point
               (cross
                 (vlax-get x 'Direction) '(0.0 1.0 0.0)))))) (cdr (reverse ObjLst)))))

 (setvar 'TILEMODE otl)
 (princ))
          

Posted

So just to try it out, I copied the system ucs's to my own named ucs's named Top, Front, Right, Left, Back, and Bottom and tried to run my lisp above... Now when ran within the lisp I get "Top" for sfv and when I copy paste the "(setq sfv (getvar 'ucsname))" line into the command line I get "Front". I really don't understand what's going on.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...