Jump to content

Recommended Posts

Posted

Can someone please help me, tell me or explain to me how to create new layer with lisp. Layer with defined parameters such as (line type, color of the line, line wight and name of the layer.

 

I'm kind a new to this so please don't be harsh :)

Posted
(defun Layer (Nme Col Ltyp LWgt Plt)
 (entmake (list (cons 0 "LAYER")
                (cons 100 "AcDbSymbolTableRecord")
                (cons 100 "AcDbLayerTableRecord")
                (cons 2  Nme)
                (cons 70 0)
                (cons 62 Col)
                (cons 6 Ltyp)
                (cons 290 Plt)
                (cons 370 LWgt))))

Posted

Already?!? :)

...so... basically what I need that for.

I'm working with with Autocad on the daily basis and I recently find out about LISPS (don't judge me...yes..I'm a newb :) ) so... I wanted to speed things up a bit. I don't want to create same layers on different drawings and repeat the same routines on each layer...such as name of the layer,color,type,line weight etc.

For instance:

001_Urban_Areas , line type continuous,line weight default,color 25.

So, when I press shortcut UA it creates layer with defined name (in this case "001_Urban_Areas), line type,line weight and default colors. I doing my best to explain :)

 

....can u pls write me example with defined shortcut..once again sorry for my ingnorance.

 

Thx for such speed answer

Posted

(defun c:UA ()
 (entmake
   (list
     (cons 0 "LAYER")
     (cons 100 "AcDbSymbolTableRecord")
     (cons 100 "AcDbLayerTableRecord")
     '(2 . "001_Urban_Areas")
     '(70 . 0)
     '(62 . 25)
     '(6 . "Continuous")
     )
   )
 (princ)
 )

 

 

(defun c:UA ()
 (command "_.Layer" "_Make" "001_Urban_Areas" "_Color" "25" "" "LType" "Continuous" "" "")
 (princ)
 )

Posted (edited)

Infact...i wanted to ask u...what 's the difference between

This code

(defun c:UA ()
 (entmake
   (list
     (cons 0 "LAYER")
     (cons 100 "AcDbSymbolTableRecord")
     (cons 100 "AcDbLayerTableRecord")
     '(2 . "001_Urban_Areas")
     '(70 . 0)
     '(62 . 25)
     '(6 . "Continuous")
     )
   )
 (princ)
 )

 

and this one

 

(defun c:UA ()
 (command "_.Layer" "_Make" "001_Urban_Areas" "_Color" "25" "" "LType" "Continuous" "" "")
 (princ)
 )

Edited by Loque
Posted
Can someone please help me, tell me or explain to me how to create new layer with lisp. Layer with defined parameters such as (line type, color of the line, line wight and name of the layer.

 

I'm kind a new to this so please don't be harsh :)

 

Being polite, here's a couple of suggestions:

 

  • Post unrelated questions in your own thread
  • Use
     when posting code

    o:)

Posted
Being polite, here's a couple of suggestions:

 

  • Post unrelated questions in your own thread
  • Use
     when posting code

    o:)

     

    :shock: I should've said the same thing, my bad Renderman

Posted
:shock: I should've said the same thing, my bad Renderman

 

No worries; Nobody can do it all by themselves... Especially me. :beer:

Posted
Being polite, here's a couple of suggestions:

 

  • Post unrelated questions in your own thread
  • Use
     when posting code

    o:)

     

    I echo those sentiments. Particularly the Code Tag usage.

     

    New thread created.

Posted
I echo those sentiments. Particularly the Code Tag usage.

 

New thread created.

 

*Tips hat*

 

T.I.-TIP-OF-THE-HAT.jpg

Posted

Re the question whats the difference not much both work.

 

If your serious about writing lots of programs then the entmake "make an entity" is probably a better way to go, good programing uses predefined subroutines or with lisp defuns that can be called by other routines often its a single line call that replaces multiple lines of code that would have to be repeated.

 

In the entmake example the name etc is a variable so you could call the entmake as often as you like just changing the layer name variable, in the second answer the layer name is "hard" coded no chance to reuse or to change so would need this line for every layer and if you change your layer naming convention you would have to rewrite all the layer names.

 

As an example I was involved in an architectural project it had an external database of all the layers to be used and the programs match the type of object, wall etc used a wall layer, we could not use hard coding because we didn't know the name of the layer to be used but you can set it to a variable.

 

(setq nme "layer1"
Col 2 
Ltyp continuous
LWgt 1
Plt "Y")
(Layer Nme Col Ltyp LWgt Plt)
(setq nme "layer2"
Col 3 
Ltyp dashed
LWgt 3
Plt "N")
(Layer Nme Col Ltyp LWgt Plt)

Posted (edited)

If your looking for a way insert mutlibule layers easly into a new drawing.

 

1. Anotherway of doing it is to create an drawing with all the nessasry layers

2. create a script (see below) to insert as block and then delete and purge.

;----------------------------------------------------------------------------
; load layers
;----------------------------------------------------------------------------
insert
layer-import.dwg
0,0,0
1 1 0
;----------------------------------------------------------------------------
; unload import layer block
;----------------------------------------------------------------------------
ssx 
block
layer-import
_.erase P 
;----------------------------------------------------------------------------
; purge old layer AND BLCOKS
;----------------------------------------------------------------------------
setbylayer all  yes yes
purge
block layer-import n
qsave

Sorry the spaces will need to be tested im a lisper not a scripter

 

The advantages of using this tecknique are:

1. Can modify the layer/s you want to insert with the usaly autocad menu

2. simple

 

The disavantages:

1. Less reliable than lisp

2. slower than lisp too run (i think?)

3. less addaptable than lisp

 

You could always do this using a lisp to insert the block but i already had this set up.

I'm pretty new to autocad in general so tell me if im wrong guys.

Edited by SunnyTurtle
adding
Posted

I've question related to my previous question about creating layers with LISP. So, basically what I want to do...for instance...when I press UA it creates layer with defined name (in this case "001_Urban_Areas), line type,line weight and default colors.) So.. i just want to upgrade the code that pBe explained so nicely . When I press the shortcut UA I want to create a defined layer ("001_Urban_Areas") a to show some kind of a notification if it is possible..something like.. "Layer 001_Urban_Areas created".

Other question is related to the previous one...kind of ..

So..when I created lisp(more did u, then I) for every layer ("001_Urban_Areas,002_Ruraln_Areas",003_Waters..etc.)

and when i press shortcut...something like "UAP" automatically starts command polyline in layer "001_Urban_Areas" with all defined parameters (color,line weight,line type, etc.) so my question i s basically is this possible?

 

P.S. Once again,apologize to forum moderators in my ignorance about forum "laws"

Posted
I've question related to my previous question about creating layers with LISP. So, basically what I want to do...for instance...when I press UA it creates layer with defined name (in this case "001_Urban_Areas), line type,line weight and default colors.) So.. i just want to upgrade the code that pBe explained so nicely . When I press the shortcut UA I want to create a defined layer ("001_Urban_Areas") a to show some kind of a notification if it is possible..something like.. "Layer 001_Urban_Areas created".

 

(defun Layer (Nme Col Ltyp LWgt)
 (entmake (list (cons 0 "LAYER")
                (cons 100 "AcDbSymbolTableRecord")
                (cons 100 "AcDbLayerTableRecord")
                (cons 2  Nme)
                (cons 70 0)
                (cons 62 Col)
                (cons 370 LWgt)))
(princ (strcat "\n " Nme " created: "))
(princ)
)
(defun c:ua ()
  (Layer "001_Urban_Areas" 25  "Continuous" -3)
  (setvar 'Clayer "001_Urban_Areas")
 (princ)
 )
(defun c:uR ()
  (Layer "002_Ruraln_Areas" 30  "Hidden" -3)
  (setvar 'Clayer "002_Ruraln_Areas")
 (princ)
 )

 

and when i press shortcut...something like "UAP" automatically starts command polyline in layer "001_Urban_Areas" with all defined parameters (color,line weight,line type, etc.) so my question i s basically is this possible?

 

That can be done but i adivise againts it. ;)

Posted

Many years ago we did some work for a massive world wide company they removed the menus all together and had only option commands like what you want you had a menu line that was a UAP, the reason behind this was to ensure the immense amount of people working on the project had only one set of standards.

 

If you want UAP UAL etc I would put them on toolbars or menus else your going to end up with lots of defuns, dont forget menus can cassacade. -> &

Posted (edited)
That can be done but i adivise againts it.

 

Why is that? Oh and pBe...thx, once again u helped me .

 

 

Many years ago we did some work for a massive world wide company they removed the menus all together and had only option commands like what you want you had a menu line that was a UAP, the reason behind this was to ensure the immense amount of people working on the project had only one set of standards.

 

If you want UAP UAL etc I would put them on toolbars or menus else your going to end up with lots of defuns, dont forget menus can cassacade. -> &

 

I was thinking about that... I need first to sort and create layers with defined parameters that follows the law of urban planing (there are special defined colors for each layer...like "Urban_areas".."rural_areas" etc.)

...so I leave that aside for now...

 

I was meaning to ask ..for instance...when I'm vectorinzg some areas on topographic maps (such as..lakes, forests, mining areas...etc.) it happens that when I'm using polyline.. it doesn't snap on the end point it's a bit longer or it snaps on the other object that is on different layer etc...problems problems...so..when I'm having like hundreds of areas and I want to calculate sum of all areas I can't do it coz there are some miss clicks during vectoring. So...I was wondering can some routine visualize problems like.. create a small circle near edge that didn't snap right or it snapped on different object ...like basic topology..something like that.

Edited by Loque
Posted

Here's the picture..

 

 

 

43686f3e4024ab2dfd6080b8bfc3de4a.png

 

to basically visualize and create small circles to point out errors...(circles, triangles, rectangles... nvm)

Posted (edited)

Using the code that pBe posted, how do you create several layers at once?

 

 
(defun c:UA ()
 (entmake
   (list
     (cons 0 "LAYER")
     (cons 100 "AcDbSymbolTableRecord")
     (cons 100 "AcDbLayerTableRecord")
     '(2 . "001_Urban_Areas")
     '(70 . 0)
     '(62 . 25)
     '(6 . "Continuous")
     )
   )
 (princ)
 )

Edited by ILoveMadoka
format
Posted

Personally I think writing a script file would be easier and less of a hassle as well it can be used in a batch script process with Batch Script Pro. Since your new to this sort of thing script files can be created by anyone that can use AutoCad and doesn't have LISP language experience. However I would encourage you to learn LISP since it opens up another world to you that can make you more skillful and productive.

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