Jump to content
skotseno

Issue With Layers

Recommended Posts

skotseno

I am new to this but I need a lisp that would create the following layers with every (even pre existing) files that I open.

 

Layer: 1 in cyan, 2 in white, 2L in white, 3 in red, 4 in yellow, 5 in white, 6 in blue, SK1 in cyan, SK2 in white, SK3 in red, SK4 in yellow, and SK6 in blue.

 

I have looked at existing lisps and macros but I am new and am having trouble making sense of them.

Share this post


Link to post
Share on other sites
MSasu

I think this will do the trick; please try to fill by yourself the remaining cases:

(foreach layerItem '([color=blue][color=red]("1" 4) [color=orange]("2" 7)[/color][/color] ("2L" 7)[/color])
(entmake (list '(0 . "LAYER") '(100 . "AcDbSymbolTableRecord") '(100 . "AcDbLayerTableRecord")
               (cons 2 (car layerItem)) '(70 . 0) (cons 62 (cadr layerItem)) '(6 . "Continuous")))
)

Share this post


Link to post
Share on other sites
BlackBox
I am new to this but I need a lisp that would create the following layers with every (even pre existing) files that I open.

 

Layer: 1 in cyan, 2 in white, 2L in white, 3 in red, 4 in yellow, 5 in white, 6 in blue, SK1 in cyan, SK2 in white, SK3 in red, SK4 in yellow, and SK6 in blue.

 

I have looked at existing lisps and macros but I am new and am having trouble making sense of them.

 

Why not simply make these layers part of your template? :unsure:

 

I think this will do the trick; please try to fill by yourself the remaining cases:

(foreach layerItem '([color=blue][color=red]("1" 4) [color=orange]("2" 7)[/color][/color] ("2L" 7)[/color])
(entmake (list '(0 . "LAYER") '(100 . "AcDbSymbolTableRecord") '(100 . "AcDbLayerTableRecord")
               (cons 2 (car layerItem)) '(70 . 0) (cons 62 (cadr layerItem)) '(6 . "Continuous")))
)

 

Building on Mircea's post, here's a Visual LISP adaptation:

 

((lambda (oLayers / layerName)
  (foreach layerItem '(("1" 4) ("2" 7) ("2L" 7))
   (vla-put-color
     (apply
       (if (tblsearch "layer" (setq layerName (car layerItem)))
        'vla-item
        'vla-add
       )
       (list oLayers layerName)
     )
     (cadr layerItem)
   )
  )
)
 (vla-get-layers
   (vla-get-activedocument (vlax-get-acad-object))
 )
)

Share this post


Link to post
Share on other sites
MSasu
Why not simply make these layers part of your template?

That was my first thought also, but next notified that OP was looking to have that layer structure created on existing drawings too.

Share this post


Link to post
Share on other sites
BIGAL

Old fashioned script will do also just open in notepad add layers change etc

 

-la
n layer1 C layer1 1
n layer2 C layer2 2
n layer3 C layer3 3

Share this post


Link to post
Share on other sites
skotseno

Thanks Lee Mac! I tried posting this code into acaddoc but nothing happens. please advise.

 

(defun _layer3 ( name color linetype lineweight plot )

(if (null (tblsearch "LAYER" name))

(entmake

(list

'(0 . "LAYER")

'(100 . "AcDbSymbolTableRecord")

'(100 . "AcDbLayerTableRecord")

'(70 . 0)

(cons 1 name)

(cons 6 linetype)

(cons 4 colour)

(cons 290 plot)

(cons 15 lineweight)

)

)

)

)

 

(_layer3 "2" 7 "Continuous" 15 1)

(_layer3 "2L" 7 "Continuous" 15 1)

(_layer3 "3" 1 "Hidden" 15 1)

(_layer3 "4" 2 "Center" 15 1)

(_layer3 "SK1" 4 "Continuous" 15 1)

(_layer3 "SK2" 7 "Continuous" 15 1)

(_layer3 "SK3" 1 "Hidden" 15 1)

(_layer3 "SK4" 2 "Center" 15 1)

Share this post


Link to post
Share on other sites
Lee Mac

Firstly, please use Code Tags when posting code.

 

You haven't copied the code correctly, the DXF group codes are wrong...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×