hello again!!!! i come back which other question.
How do I select the layer in which I want to draw?
for example i draw two line and Each of them has to be in different layer.
How do I select the layer which I want to draw?
sorry for my english.
Is the layer pulldown not sufficient (in a toolbar and/or the ribbon), or selecting from the layer manger?
(setvar 'clayer "Layer1")
(command "_pline" p1 p2 "")
(setvar 'clayer "Layer2")
(command "_pline" p3 p4 "")
Another
(defun c:test (/ *error* old_lay) (defun *error* (msg) (setvar "clayer" old_lay) (princ) );; *error* (setq old_lay (getvar "clayer")) (command "_.layer" "_t" "line1" "_m" "line1" "_c" "1" "" "") (command "_.line" pause pause "") (command "_.layer" "_t" "line2" "_m" "line2" "_c" "2" "" "") (command "_.line" pause pause "") (*error* nil) );; test
Henrique
@andresep82 wrote:....
How do I select the layer in which I want to draw?
for example i draw two line and Each of them has to be in different layer.
How do I select the layer which I want to draw?
....
[I see others have written in with similar suggestions -- I had written much of this out but got distracted for a while.]
I assume you are talking about building this into a routine of some kind, rather than using alanjt's suggestions about Layer setting, and that you would get the Line enpoints within the routine, rather than smaher12's approach with point variables -- those other ways are fine if I assumed wrong.
There are several ways you could do it:
[consolidated compared to hmsilva's, into one (command) function:]
(command
"_.layer" "_set" "FirstLineLayerName" ""
"_.line" pause pause ""
"_.layer" "_set" "SecondLineLayerName" ""
"_.line" pause pause ""
); end command
or
[like smaher12's but with internal User input:]
(setvar 'clayer "FirstLineLayerName")
(command "_.line" pause pause "")
(setvar 'clayer "SecondLineLayerName")
(command "_.line" pause pause "")
or you could also draw the Lines and use CHPROP on each to put it on the Layer you want it on after drawing it, which saves you the need to set a current Layer [and to set it back if desired]:
(command
"_.line" pause pause ""
"_.chprop" "_last" "" "_layer" "FirstLineLayerName" ""
"_.line" pause pause ""
"_.chprop" "_last" "" "_layer" "SecondLineLayerName" ""
)
Incorporate some elements from others' suggestions, about ensuring the Layers exist, error handling, etc., as you need to.
[I would recommend against smaher12's suggestion that draws Polylines, unless you first make sure the PLINEWID System Variable is set to 0, and unless there's some reason that using Polylines will do something for you that Lines won't -- with a single line segment, Polylines take more memory than Lines.]
@smaher12 wrote:
@Kent1Cooper wrote:Polylines take more memory than Lines.
Good to know... Thanks Kent
The difference is not very much, and these days maybe not much worth worrying about. I know about it mostly from way back in the mid-'80s when memory was expensive, hard drives were small [the first computer this office got had a 10MB hard drive!], and when LWPolylines didn't exist yet. One of the reasons for their coming into existence was to reduce memory consumption compared to "heavy" ones. But even today, if you drew a whole drawing using no Lines but always single-line-segment Polylines, it could add up, and could detectably affect the time it takes to open or regenerate or save a drawing.
Also, when you get up past [I forget where the break is, but way back then I did some comparisons, and it was roughly] three or four segments, a Polyline takes less memory than the same drawn content would take if made up of separate Lines and/or Arcs. [I think the break point might be a little different for Lines than it is for Arcs.] That's one of the reasons for Polylines existing in the first place, even the "heavy" ones. It mostly has to do with saving information on the Layer and other Properties only once for the whole Polyline, no matter how many segments it has, rather than separately for each Line or Arc entity, and with having fewer defining points, since a vertex [other than at an open end] stores information in one entry that would need to be stored twice with separate Lines sharing a common end point.
Just an example ...
(defun c:Test (/ p1 p2) (if (not (tblsearch "LAYER" "Line No-1")) (command "_.-layer" "_make" "Line No-1" "_color" 1 "" "") ) (if (not (tblsearch "LAYER" "Line No-2")) (command "_.-layer" "_make" "Line No-2" "_color" 2 "" "") ) (if (and (setq p1 (getpoint "\n Specify start point :")) (setq p2 (getpoint "\n Second point :" p1)) (entmakex (list '(0 . "LINE") (cons 10 p1) (cons 11 p2) '(8 . "Line No-1") ) ) (setq p1 p2 p2 (getpoint "\n Next point :" p1) ) (entmakex (list '(0 . "LINE") (cons 10 p1) (cons 11 p2) '(8 . "Line No-2") ) ) ) (princ "\n Well done !!") ) (princ) )
@_Tharwat wrote:Just an example ...
....
(setq p1 p2 p2 (getpoint "\n Next point :" p1) ) ....
That one assumes [just so the OP knows -- it may well be a correct assumption, though I didn't interpret the question that way] that the second Line is a continuation of the first Line, starting at the first one's endpoint.
@Kent1Cooper wrote:
@_Tharwat wrote:Just an example ...
....
(setq p1 p2 p2 (getpoint "\n Next point :" p1) ) ....
That one assumes [just so the OP knows -- it may well be a correct assumption, though I didn't interpret the question that way] that the second Line is a continuation of the first Line, starting at the first one's endpoint.
Since the OP' English is weak and the request is not that clear as well , besides that the request is also without any sample drawing or a snapshot , everything still just a matter of shooting in the dark .
yeah¡¡¡¡¡¡
thanks¡¡¡¡¡¡¡¡ created layer if I it does not exist.....
(if (not (tblsearch "LAYER" "Line No-1")) (command "_.-layer" "_make" "Line No-1" "_color" 1 "" "") ) (if (not (tblsearch "LAYER" "Line No-2")) (command "_.-layer" "_make" "Line No-2" "_color" 2 "" "") )
and change the layer when i need it......
(setvar 'clayer "Layer1") (command "_pline" p1 p2 "") (setvar 'clayer "Layer2") (command "_pline" p3 p4 "")
I continue learning
Consider this
(foreach lay '(("Line No-1" 1) ("Line No-2" 2)) (if (not (tblsearch "LAYER" (Car lay))) (command "_.-layer" "_make" (Car lay) "_color" (cadr lay) "" "") ))
Tell us how are you planning to implement the "layer change per line" routine andresep82?
There's probably a better approach for what you wanting to do.
@andresep82 wrote:yeah¡¡¡¡¡¡
thanks¡¡¡¡¡¡¡¡ created layer if I it does not exist.....
(if (not (tblsearch "LAYER" "Line No-1")) (command "_.-layer" "_make" "Line No-1" "_color" 1 "" "") ) (if (not (tblsearch "LAYER" "Line No-2")) (command "_.-layer" "_make" "Line No-2" "_color" 2 "" "") )I continue learning
You're welcome
pbejse
for example:
I draw a stairs.
which lips i define initial point Width and Length of step...etc,etc....
the exterior line(rail) it has a color, the interior line(step) it has other color and the tour line it has other color.
i change the layer when i draw line at lips.
sorry for my english.
@andresep82 wrote:....
for example:
I draw a stairs.
which lips i define initial point Width and Length of step...etc,etc....
the exterior line(rail) it has a color, the interior line(step) it has other color and the tour line it has other color.
i change the layer when i draw line at lips.
....
For that particular kind of application, you may want to look at this:
http://cadtips.cadalyst.com/misc-user-tools/tip-2294-draw-stairs-plan-view
Despite the heading and description, it contains two commands [as I commented there], to draw either a plan or a section. You may not want to do certain things in the way that it does, and you would at least probably want to change Layer names and colors. It makes sure the Layers are there in a simpler way [it's not really necessary to test whether they exist], and offers lots of default values based on Building Code and accessibility requirements common here in the US, which you would presumably change. But it does do what you're looking for here, using different Layers for different elements, changing between them automatically, so you might at least use it as an example of a way to do that. It has a rather detailed description of how the commands work at the top of the file.
[It must be worth something, because for a long time it was the fourth most downloaded Tip out of over 4,000 on their site. It has "fallen" to currently eighth most downloaded, but that's still pretty good -- in the top 1/5 of 1%. There are also other stair-related routines there on the Cadalyst CAD Tips site.]
ohhhh¡¡¡ excelent page¡¡¡¡ many many examples to study and learn.
the rutine is very complicated,I am beginning programming But always it is good to have examples.when you programming knowing what you need .... it adjusts to you.
thanks¡¡¡¡¡¡
@Anonymous wrote:Hi Tharwat. I am new to lisp and found it very useful. Could you make another code similar to this but with only one layer to be created and allow to creat many lines? Thank you.
Hi .
What is the way you are looking for to create lines ? do you have a list of coordinates or by user picks on screen ?
What is the layer name you want to create and its properties ?
@Anonymous wrote:I want to type a command like ALUM, then a layer will be automatically created and set as default
and at the same time bring me to Polyline command.
Layer Properties
LayerName: ALUM
LayerColor: 3
Linetype: ByLayer
LineWieght: 3
Best regards.
This ?
(defun c:alum nil (if (not (tblsearch "LAYER" "ALUM")) (entmake (list '(0 . "LAYER") '(100 . "AcDbSymbolTableRecord") '(100 . "AcDbLayerTableRecord") '(2 . "ALUM") (cons 70 0) '(62 . 3) '(6 . "ByLayer") '(370 . 30) ) ) ) (setvar 'CLAYER "ALUM") (command "_pline") (princ) )