Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Mentor
The_Caddie
Posts: 208
Registered: ‎06-08-2010
Message 1 of 6 (157 Views)

cant get the while comand right?

157 Views, 5 Replies
04-13-2012 07:31 AM

I am trying to get my original layer and lintype reinstated after the user is finished with the pline

 

I know Im suppose to use the while command but am now completely lost on which way to do this

 

Could somebody help with this?

 

Thnx…

 

(DEFUN c:TEST1 ()

(if (not (tblsearch "LTYPE" "MYWC"))
 (command "-linetype" "LOAD" "MYWC" "C:/COUNTER.LIN" "")
)


;SECOND PROGRAM...

;CREATE CORESPONDING LAYER...
(command "._Layer" "Make" "WC LEIDING" "Ltype" "Continuous" "" "Color" "211" "" "")


(SETQ MYOLDCELTYPE (GETVAR "CELTYPE"))

(SETVAR "CELTYPE" "MYWC")

(while (PROGN

(COMMAND "pline")

(SETVAR "CELTYPE" MYOLDCELTYPE)

)

)

 

*Expert Elite*
Kent1Cooper
Posts: 5,513
Registered: ‎09-13-2004
Message 2 of 6 (151 Views)

Re: cant get the while comand right?

04-13-2012 07:49 AM in reply to: The_Caddie

The_Caddie wrote:

I am trying to get my original layer and lintype reinstated after the user is finished with the pline

 

I know Im suppose to use the while command but am now completely lost on which way to do this

 

....

(SETQ MYOLDCELTYPE (GETVAR "CELTYPE"))

(SETVAR "CELTYPE" "MYWC")

(while (PROGN (COMMAND "pline")

(SETVAR "CELTYPE" MYOLDCELTYPE)

....


You need to start the command first, then go into a (while) function to keep waiting for user input until the command is completed:

 

....
(SETQ MYOLDCELTYPE (GETVAR "CELTYPE"))
(SETVAR "CELTYPE" "MYWC")
(COMMAND "pline")
(while (> (getvar 'cmdactive) 0) (command pause))
(SETVAR "CELTYPE" MYOLDCELTYPE)
....

 

Another thing you could instead is to eliminate the check on whether the Linetype is in the drawing and the loading of it if it's not, eliminate the saving and restoring of the current-Linetype System Variable, and just do this:

 

....

(COMMAND "pline")
(while (> (getvar 'cmdactive) 0) (command pause))

(command "_.chprop" "_last" "" "_ltype" "MYWC" "")

....

 

If the linetype is not already loaded, (setvar 'celtype) will fail, but the CHPROP command will find it, so you don't need to load it first.

Kent Cooper
Mentor
balisteor
Posts: 339
Registered: ‎02-23-2009
Message 3 of 6 (147 Views)

Re: cant get the while comand right?

04-13-2012 07:54 AM in reply to: The_Caddie

 


While is a loop, try to think of it in really simple terms

(while (= go T)
;;; no need for progn
;; do some stuff, but when finished with your stuff be sure while will end. by setting the condition

(setq go nil) ;; next time it checks it will stop the loop
);

Mentor
The_Caddie
Posts: 208
Registered: ‎06-08-2010
Message 4 of 6 (113 Views)

Re: can't get the while command right?

04-16-2012 01:45 AM in reply to: balisteor

I don't know what I was thinking last Friday but I posted something that makes no sense the following is better...

(DEFUN c:test1 ()


(if (not (tblsearch "ltype" "MYWC"))
(command "-linetype" "Load""MYWC" "C:/COUNTER.LIN" "")
(command ".-Layer" "Make" "WC Leiding" "ltype" "MYWC" "" "Color" "211" "" "")
)

(setvar "CLAYER" "WC Leiding")


(command "_.Pline")
(while (= (logand (getvar "CMDACTIVE") 1) 1)
(command pause)
)

(command "layerp")

)

  however for some reason the WC Leiding layer wont accept the line type. when the command is instigated the command seams to work perfectly however on exiting the linetype MYWC is sudernly droped from the layer and changed to continuous????

 

Sorry about the woeful post Friday (Friday the 13th ill stick with that excuse)

*Expert Elite*
pbejse
Posts: 2,500
Registered: ‎11-24-2009
Message 5 of 6 (105 Views)

Re: can't get the while command right?

04-16-2012 04:38 AM in reply to: The_Caddie

 

(command "layerp") <-- there lies your problem

 

Command: -layer

Current layer:  "0"
Enter an option ........../Unlock/stAte/Description/rEconcile]: M

Enter name for new layer (becomes the current layer) <WC Leiding>: Banana
Enter an option  ......./Unlock/stAte/Description/rEconcile]: LT

Enter loaded linetype name or [?] <Continuous>: Hidden

Enter name list of layer(s) for linetype "hidden" <Banana>:
Enter an option  /Unlock/stAte/Description/rEconcile]: ENTER

 

Then right after that :

Command: _LayerP
Restored previous layer status.

 

See what happens.

 

The newly created layer remains but the Hddien linetype were revert back to its default

 

I'm guessing you meant

(setvar 'CLAYER lay) wherein from the beginning you invoke (setq lay (getvar 'CLayer))

 

Layer MAKE will set the newly craeted layer current. Whiles Layer NEW will add the layer to the current drawing layer collection

 

Not sure that will help you at all though.

 

 

*Expert Elite*
Kent1Cooper
Posts: 5,513
Registered: ‎09-13-2004
Message 6 of 6 (100 Views)

Re: can't get the while command right?

04-16-2012 06:01 AM in reply to: The_Caddie

The_Caddie wrote:

...

(DEFUN c:test1 ()


(if (not (tblsearch "ltype" "MYWC"))
(command "-linetype" "Load""MYWC" "C:/COUNTER.LIN" "")
(command ".-Layer" "Make" "WC Leiding" "ltype" "MYWC" "" "Color" "211" "" "")
)

(setvar "CLAYER" "WC Leiding")


(command "_.Pline")
(while (= (logand (getvar "CMDACTIVE") 1) 1)
(command pause)
)

(command "layerp")

)

  however for some reason the WC Leiding layer wont accept the line type. when the command is instigated the command seams to work perfectly however on exiting the linetype MYWC is sudernly droped from the layer and changed to continuous????

....


I was a little surprised by what pbejse pointed out, too, but the Command Reference confirms it -- LAYERP undoes color and linetype and other settings, but doesn't undo the creation of a new Layer, even if that was within the options in the same LAYER command that includes the settings it does undo.

 

By the way, like CHPROP, the LAYER command can find a linetype even if it's not loaded, so you don't need to check for it or load it, if you are assigning it to a Layer from the Ltype option within a Layer command.

 

You could make the Layer with the New option so that it's not set current, and then use a separate LAYER command to set it current so that that's all that gets undone by Layerp.  Or you could draw the Polyline on whatever Layer happens to be current, and then use CHPROP to change it to the desired Layer, eliminating any need to save and reset the current Layer name or to use something like Layerp.

Kent Cooper
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.