Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

cant get the while comand right?

5 REPLIES 5
Reply
Message 1 of 6
The_Caddie
323 Views, 5 Replies

cant get the while comand right?

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)

)

)

 

5 REPLIES 5
Message 2 of 6
Kent1Cooper
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, AIA
Message 3 of 6
balisteor
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
);

Message 4 of 6
The_Caddie
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)

Message 5 of 6
pbejse
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.

 

 

Message 6 of 6
Kent1Cooper
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, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

”Boost