Polyline with Width and Color

Polyline with Width and Color

Libbya
Mentor Mentor
4,171 Views
5 Replies
Message 1 of 6

Polyline with Width and Color

Libbya
Mentor
Mentor

I have a small amount of experience with LISP and Macros but feel a bit stuck with this.  I would like a command that allows me to draw a polyline with any number of points.  I would like the polyline to go on a specific layer (A-Section), be a specific width (2-5/16"), be a spedific color (175 - not bylayer) and a specific linetype (center - not bylayer).  I would also like to be able to select a varied number of points before exiting the command.

 

Initially I was working with a macro and can start the correct layer and create the polyline of the correct width but I do not know how to set the color and linetype which are not bylayer.

 

I was then working on making a LISP, but I am stuck on allowing an unspecified number of points and still being able to change the properties that are not bylayer.

 

Any help would be appreciated.

0 Likes
4,172 Views
5 Replies
Replies (5)
Message 2 of 6

ВeekeeCZ
Consultant
Consultant

@Libbya wrote:

...

 

Initially I was working with a macro and can start the correct layer and create the polyline of the correct width but I do not know how to set the color and linetype which are not bylayer.

 

I was then working on making a LISP, but I am stuck on allowing an unspecified number of points and still being able to change the properties that are not bylayer.

 

Any help would be appreciated.


variables:

CECOLOR

CELTYPE

How would you know a correct order of points to connect them with PLINE? Post a dwg sample... And if you have some lisp code, post it as well..

Message 3 of 6

Kent1Cooper
Consultant
Consultant

For the color and linetype, you can either set them ahead of time as BeekeeCZ suggests, or you can impose them on the Polyline after it's drawn with a CHPROP command, or by other means such as (subst) & (entmod) or via VLA properties.

 

As for drawing a Polyline with an unknown number of vertices, that's the classic issue of waiting for further User input within a command until the command is completed before going on to the next thing [such as the CHPROP mentioned above].  You use the CMDACTIVE System Variable, which checks whether a CoMmanD is ACTIVE:

 

(command "_.pline"); leaves you in the Pline command

(while (> (getvar 'cmdactive) 0); as long as the command isn't finished yet

  (command pause); take User input in response to the command's prompts

); while

(....then on to whatever follows....)

Kent Cooper, AIA
Message 4 of 6

Libbya
Mentor
Mentor

Thank you very much, both of you.  That's very helpful.  

 

With those variables, I went back to the macro version.  Here's where I'm at:

 

^C^C-layer;m;PS-Section;c;blue;PS-Section;;cecolor;175;-ltype;l;center;;;celtype;center;_pline \w;2.3125;;

The issue I am currently having is that some files have the 'Center' linetype loaded and some do not.  The above macro works fine if the Center linetype has not been loaded, but gives 'Invalid option keyword.' if Center already exists in the file because if it exists, it asks whether or not you want to reload it.  If I add one more enter before celtype then it works if Center is loaded, but fails in a similar manner the first time it is run in a file if the Center linetype does not yet exist in the file.  

 

Is there a way to resolve that discrepancy?

 

I also find that after the command has been run and I am finished making the polyline, the cecolor and celtype remain set as they were in the macro.  Is there a way to allow an indefinite number of points to the polyline and still reset those variables?  Is it possible to also set the layer back to what it was prior to running the macro? 

0 Likes
Message 5 of 6

Kent1Cooper
Consultant
Consultant

@Libbya wrote:

.... some files have the 'Center' linetype loaded and some do not.  The above macro works fine if the Center linetype has not been loaded, but gives 'Invalid option keyword.' if Center already exists in the file because if it exists, it asks whether or not you want to reload it.  If I add one more enter before celtype then it works if Center is loaded, but fails in a similar manner the first time it is run in a file if the Center linetype does not yet exist in the file.  

 

Is there a way to resolve that discrepancy?

 

.... after the command has been run and I am finished making the polyline, the cecolor and celtype remain set as they were in the macro.  Is there a way to allow an indefinite number of points to the polyline and still reset those variables?  Is it possible to also set the layer back to what it was prior to running the macro? 


There's an advantage here to using CHPROP after something is drawn -- it doesn't matter whether a linetype is already loaded in the drawing or not; if not, it will find it without the need for loading it previously, unlike the setting of the CELTYPE System Variable.  However, to do it that way, you may need an AutoLISP routine rather than a macro [though you can then have a macro that calls for the routine].  Some Lisp functions can be used in macros, but I'm not sure what the limitations are, nor whether the (while) thing looking at CMDACTIVE is one of them -- try it out.  If it doesn't allow that, look into setting the EXPERT System Variable -- it may have a setting that will prevent that question from being asked.

 

There are countless routines on this Forum that save the current values of various System Variables at the beginning, change them for whatever reasons they have, and set them back at the end to what they were before.  Search for (getvar 'clayer ... or (getvar "clayer" ... [both (getvar) and (setvar) functions work with either an asterisk-prefixed or a double-quotes-wrapped System Variable name] to find things that include the saving of the current Layer name, which will later use (setvar 'clayer ... or a Layer command's Set option, followed by whatever variable name they used, at the end somewhere, to put it back.  In between they will have either a (setvar 'clayer ... function to some other Layer, or a Layer command with the Set or Make option in it.  Again, I'm not sure about using those in a macro, but they are standard fare in Lisp routines.  The same approach is used for all manner of CE... System Variables in addition to CELTYPE, as well as OSMODE, CMDECHO, BLIPMODE, UCSFOLLOW, EXPERT, QAFLAGS, etc.

Kent Cooper, AIA
Message 6 of 6

Libbya
Mentor
Mentor

I appreciate the input.  Here's what I came up with that seems to work exactly the way I wanted:

 

(defun c:SLN
  ( / CASV LW CL)
  (setq CASV (/ 1.0 (getvar "cannoscalevalue")))
  (setq LW (* 0.0240885417 CASV))
  (setq CL(getvar "clayer"))
  (command "orthomode" 0)
  (command "-layer" "m" "PS-Section" "c" "blue" "" "")
  (command "pline")
  (while (> (getvar 'cmdactive) 0)
  	(command pause))
  (command "chprop" "_last" "" "c" "175" "lt" "center" "")
  (command "pedit" "_last" "w" LW "")
  (setvar "clayer" CL)
  (princ)
  )
0 Likes