Jump to content

Named UCS and PLAN all in one LISP not working


Recommended Posts

Posted

I don't want to give the answer away too much, as you seem to want to work things out for yourself - but here's a hint:

 

play around a bit with the "layoutlist" function.

  • Replies 51
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    21

  • skipsophrenic

    17

  • uddfl

    4

  • GE13579

    3

Posted

Wasn't able to do much with LAYOUTLIST but got somewhere with LAYOUT.

 

Can someone just look at this if function and never mind where i went wrong - did i get ANY of it right as it's throwing not working.

 

I'm trying to get it so the user can either select an active viewport

and run the plan command in that or if no viewport active, then

prompt the user to specify it's boundary's so as it'll draw one .

 

(defun c:ucsplan (/ uNm)
 (if (and (setq uNm (getstring t "\nSpecify Name of UCS: "))
   (tblsearch "UCS" uNm)
     )
   (progn
     (command "_ucs" "NA" "R" uNm)
     (command "_plan" "c")
   )
   (princ "\nUCS Name not Found. ")
 )
 (Command "layout" "Set")
 (if (and (setq vprt (getobj t "\nSelect Vieprort")
  (vport (getpoint t "\nSelect First Corner")
  (getpoint t "\nSelect Second Corner")
  )
   (princ)
   )
     )
 )
)

Posted

I can't really tell you because I don't know what the getobj and the vport functions do.

Posted

have you got separately defined local functions "getobj" and "vport"?

 

If you are mistaken and these are not local functions, then maybe the use of entsel would be in order.

 

Also, when using your "getpoint" functions, the argument in place of "t" would need to be a point argument ~ only the getstring function uses the "t" argument to allow spaces.

Posted

So although I'm using the wrong options, i'm on the right track with using an if statement?

Posted
So although I'm using the wrong options, i'm on the right track with using an if statement?
You might be, but still, you have to cleanup your routine. As Lee said,

 

- You probably want to use the entsel function instead of "getobj", unless the latter is an user-defined function;

 

- Getpoint does not require 't';

 

also,

 

- (command "layout" "set") is incomplete;

 

- you don't seem to need "and" in your second 'if' (and you seem to have a few extra parenthesis)

 

- you need "progn" when using 'if' if there is more than one text expression

 

- What's a "vport" function?

Posted

sorry, I was typing the wrong thing into the code anyway, the "vport" option was to try an draw a viewport - I hadn't got it right in my own head that I need to enter "_-vports" but that's still not working, (YET! I will prevail!!!)

 

The way I've got the command layout set at the moment it pauses and waits for the users choice of ayout (Not figured out how to do layout choice by mouse yet)

 

progn??? what's that? (Sorry if that comes accross as dumb)

Posted

Not really sure what you really intend for this routine to do, but maybe for starters:

 

(defun c:ucsplan  (/ vLst oVar layLst lay)
 (setq    vLst   (list "CMDECHO" "CLAYER")
   oVar   (mapcar 'getvar vLst)
   layLst (layoutlist))
 (setvar "cmdecho" 0)
 (if (and (setq lay (getstring t "\nSpecify Name of Layout >  "))
      (member lay layLst))
   (progn
     (setvar "ctab" lay)
     (if (> (length (vports)) 1)
   (command "_.mspace")
   (progn
     (if (not (tblsearch "LAYER" "VIEWPORT"))
       (command "-layer" "M" "VIEWPORT" "")
       (setvar "CLAYER" "VIEWPORT"))
     (prompt "\nConstruct Viewport > ")
     (command "-vports" pause pause))))
   (princ "\n<!> Layout Not Found <!>"))
 (mapcar 'setvar vLst oVar)
 (princ))

Posted
the "vport" option was to try an draw a viewport

 

Try this:

(command "mview" pause pause)

 

And what do you need the "Select Viewport" option for?

 

The way I've got the command layout set at the moment it pauses and waits for the users choice of ayout (Not figured out how to do layout choice by mouse yet)
That's a good idea, but I don't think it's possible, the routine would end as soon as you switch layouts with the mouse. With LISP only, you would have to enter the layout name.

 

(command "layout" "set" pause)

 

progn??? what's that? (Sorry if that comes accross as dumb)

 

 

progn

 

You can use progn to evaluate several expressions where only one expression is expected.

 

Arguments

expr

One or more AutoLISP expressions.

 

Return Values

The result of the last evaluated expression.

Examples

The if function normally evaluates one then expression if the test expression evaluates to anything but nil. The following example uses progn to evaluate two expressions following if:

(if (= a b)
 (progn
   (princ "\nA = B ")
   (setq a (+ a 10) b (- b 10))
 )
)

Posted

Maybe an improvement:

 

(defun c:ucsplan  (/ vLst oVar layLst lay)
 (setq    vLst   (list "CMDECHO" "CLAYER")
   oVar   (mapcar 'getvar vLst)
   layLst (layoutlist))
 (setvar "cmdecho" 0)
 (if (and (setq lay (getstring t (strcat "\nSpecify Name of Layout <" (car layLst) ">:  ")))
      (or (not (eq "" lay)) (setq lay (car layLst)))
      (member lay layLst))
   (progn
     (setvar "ctab" lay)
     (if (> (length (vports)) 1)
   (command "_.mspace")
   (progn
     (if (not (tblsearch "LAYER" "VIEWPORT"))
       (command "-layer" "M" "VIEWPORT" "")
       (setvar "CLAYER" "VIEWPORT"))
     (prompt "\nConstruct Viewport > ")
     (command "-vports" pause pause))))
   (princ "\n<!> Layout Not Found <!>"))
 (mapcar 'setvar vLst oVar)
 (princ))

Posted

(defun c:ucsplan (/ uNm vLst oVar layLst lay)
 (if (and (setq uNm (getstring t "\nSpecify Name of UCS: "))
   (tblsearch "UCS" uNm)
     )
   (progn
     (command "_ucs" "NA" "R" uNm)
     (command "_plan" "c")
   )
   (princ "\nUCS Name not Found. ")
 )
)
(setq vLst (list "CMDECHO" "CLAYER")
)
oVar
(mapcar 'getvar vLst)
layLst
(layoutlist)
)
(setvar "cmdecho" 0)
(if (and (setq lay
 (getstring
   t
   (strcat "\nSpecify Name of Layout <" (car layLst) ">:  ")
 )
 )
 (or (not (eq "" lay))
     (setq lay (car layLst))
     (member lay layLst)
 )
 (progn
   (setvar "ctab" lay)
   (if (> (length (vports)) 1)
     (command "_.mspace")
     (progn
       (if (not (tblsearch "LAYER" "VIEWPORT"))
  (command "-layer" "M" "VIEWPORT" "")
  (setvar "CLAYER" "VIEWPORT")
       )
       (prompt "\nConstruct Viewport > ")
       (command "-vports" pause pause)
     )
   )
   (princ "\n<!> Layout Not Found <!>")
   (mapcar 'setvar vLst oVar)
   (princ)
 )
   )
)

 

This is really confusing now,

I've took you're suggested update lee and incorporated to into the code, but since then I keep getting different error messages when i recheck what I'VE done

 

"; error: extra right paren on input" - I can't find which one needs removing

 

and "; error: too few arguments: (IF (AND ( ... ) ( ... ) ( ... ) ... ))" for two occurences.

 

Have been workin on this on an off over w/end tryin to figure it out.

Posted

Are you typing these in Notepad? or in the Visual LISP Editor? - in the Visual LISP Editor parenthesis errors are easy to spot. :thumbsup:

 

EDIT:

 

Also, I wouldn't just wedge my code in the middle of yours... the variables will need to be stored at the beginning of the code in order to be set back to their correct values at the end.

Posted

How about this to get you by:

 

(defun c:ucsplan  (/ vLst oVar layLst lay uNme)
 (setq    vLst   (list "CMDECHO" "CLAYER")
   oVar   (mapcar 'getvar vLst)
   layLst (layoutlist))
 (setvar "cmdecho" 0)
 (if (and (setq lay (getstring t (strcat "\nSpecify Name of Layout <" (car layLst) ">:  ")))
      (or (not (eq "" lay)) (setq lay (car layLst)))
      (member lay layLst))
   (progn
     (setvar "ctab" lay)
     (if (> (length (vports)) 1)
   (command "_.mspace")
   (progn
     (if (not (tblsearch "LAYER" "VIEWPORT"))
       (command "-layer" "M" "VIEWPORT" "")
       (setvar "CLAYER" "VIEWPORT"))
     (prompt "\nConstruct Viewport > ")
     (command "-vports" pause pause)))
     (if (and (setq uNme (getstring t "\nSpecify Name of UCS:  "))
          (tblsearch "UCS" uNme))
   (progn
     (command "_ucs" "NA" "R" uNme)
     (command "_plan" "c"))
   (princ "\n<!> UCS Name Not Found <!>")))
   (princ "\n<!> Layout Not Found <!>"))
 (mapcar 'setvar vLst oVar)
 (princ))

Posted

how about this, i changed the variable names to keep my head on straight:

 

(defun c:UCSPLAN ( / *error* AT:GetVars AT:SetVars getvar_list setvar_list ucs_name layout_name vpnt_1 vpnt_2 )

;;;;; SUBROUTINES ;;;;;
;error handler
 (defun *error* (msg)
   (AT:SetVars getvar_list setvar_list)
   (princ msg)
 );defun

;get specific variables (from provided list) & store in a list
;created by: alan thompson
(defun AT:GetVars ( list_vars / )
(mapcar 'getvar list_vars)
);defun

;set specific variables (from provided list)
;created by: alan thompson
(defun AT:SetVars ( list_vars list_setvars / )
(mapcar 'setvar list_vars list_setvars)
);defun


;;;;; MAIN ROUTINE ;;;;;

;save & set variables
 (setq getvar_list (list "cmdecho" "clayer"))
 (setq setvar_list (AT:GetVars getvar_list))
 (setvar "cmdecho" 0)

;ucs & plan setup
 (if
   (and
     (setq ucs_name (getstring t "\nName of UCS to set as current: "))
     (tblsearch "ucs" ucs_name)
   );and
    (progn
      (command "_.ucs" "_r" ucs_name)
      (command "_.plan" "_c")
    );progn
    (princ (strcat "\nSorry, named UCS \""
           ucs_name
           "\" does not exist."
       );strcat
    );princ
 );if

;layout setup
; layout name
 (if
   (and
     (setq layout_name
        (getstring    t
           (strcat    "\nSpeficy Layout Name <"
               (car (layoutlist))
               ">: "
           );strcat
        );getstring
     );setq
;if "" or not a member, sets as 1st layout in layoutlist
     (if
   (or
     (eq "" layout_name)
     (not
       (member layout_name (layoutlist))
     );not
   );or
    (setq layout_name (car (layoutlist)))
     );if
     (member layout_name
         (layoutlist)
     );member
   );and
;set current layout tab
    (progn
      (setvar "ctab" layout_name)
      (if
    (> (length (vports)) 1)
     (command "_.mspace")
     (progn
;set/create viewport layer
       (if
         (not
       (tblsearch "layer" "VIEWPORT")
         );not
          (command "_.layer" "_m" "VIEWPORT" "")
          (command "_.layer" "_t" "VIEWPORT" "_s" "VIEWPORT" "")
       );if
;create viewport
       (princ "\nConstruct Viewport: ")
       (if
         (and
       (setq vpnt_1 (getpoint "\nViewport point 1: "))
       (setq vpnt_2 (getpoint vpnt_1 "\nViewport point 2: "))
         );and
            (command "_.vports" vpnt_1 vpnt_2)
       );if
     );progn
      );if
    );progn
 );if
;reset variables to original state
 (AT:SetVars getvar_list setvar_list)
 (princ)
);defun

 

btw, you don't have to type "na" when setting your ucs for new version of autocad. it will still recognize typing "R", "S", "D" & "?" after typing "ucs".

Posted

Chers peeples, i'll check this out tomorrow at work an get back to you on it

Posted

Nice one Peter - it would be nice to see if my routine meets your needs and accomplishes what you would like to achieve. :)

 

Cheers

 

Lee

Posted

Lee mac this is whats happening in command line now.

 

Command: ucsplan

Specify Name of Layout : A1 Frame

Regenerating layout.

Construct Viewport >

Specify Name of UCS: world

** Command only valid in Model space **

Unknown command "C". Press F1 for help.

 

but it's nearly there, it let's me start the viewport command, it just asking for a ucs at the wrong time at the minute

----------------------------------------

Alanjt

 

Similar errors, here's what happens in command line

 

Command: ucsplan

Name of UCS to set as current: test

Sorry, named UCS "test " does not exist.

Speficy Layout Name : A1 Frame

 

This is sfter i've saved my ucs name.

 

And when i try go to a different layout it just stops in model space happy in the knowledge that i'll want to throw computer out the window.

Posted

If so, try this:

 

(defun c:ucsplan  (/ vLst oVar layLst lay uNme)
 (setq    vLst   (list "CMDECHO" "CLAYER")
   oVar   (mapcar 'getvar vLst)
   layLst (layoutlist))
 (setvar "cmdecho" 0)
 (if (and (setq uNme (getstring t "\nSpecify Name of UCS:  "))
      (tblsearch "UCS" uNme))
   (progn
     (command "_ucs" "NA" "R" uNme)
     (command "_plan" "c")
     (if (and (setq lay (getstring t (strcat "\nSpecify Name of Layout <" (car layLst) ">:  ")))
          (or (not (eq "" lay)) (setq lay (car layLst)))
          (member lay layLst))
   (progn
     (setvar "ctab" lay)
     (if (> (length (vports)) 1)
       (command "_.mspace")
       (progn
         (if (not (tblsearch "LAYER" "VIEWPORT"))
       (command "-layer" "M" "VIEWPORT" "")
       (setvar "CLAYER" "VIEWPORT"))
         (prompt "\nConstruct Viewport > ")
         (command "-vports" pause pause))))
   (princ "\n<!> Layout Not Found <!>")))
   (princ "\n<!> UCS Name Not Found <!>"))
 (mapcar 'setvar vLst oVar)
 (princ))

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...