Manipulate the Layer Manager using VBA - or other code

Manipulate the Layer Manager using VBA - or other code

cve60069
Advocate Advocate
1,861 Views
9 Replies
Message 1 of 10

Manipulate the Layer Manager using VBA - or other code

cve60069
Advocate
Advocate

I want to manipulate the Layer Manager by adding Property and Group Filters and to add new layers using VBA or some other code that I am to run as a macro from the Manage Tab.

 

Before I start the process of writing the code, is this do-able please?

0 Likes
Accepted solutions (2)
1,862 Views
9 Replies
Replies (9)
Message 2 of 10

cadffm
Consultant
Consultant
Hi,
 
 
>>"Manipulate the Layer Manager using VBA"
 
I think you can't manipulate the Layerproperties-Manager
 

>>"I want to manipulate the Layer Manager by adding Property"

Wether existing properties, else your own properties (becaus you can not manipulate this dialog and you can not add properties to the layerobject)

Perhaps you mean that you want to edit layer properties VALUEs?

 

>>"and Group Filters"

Sure, if there are no Api-method (but I guess there is), you can also use sendcommand

to add or remove Layer Groupfilters

 

>>"and to add new layers using VBA"

No problem

 

>>"or some other code that I am to run as a macro from the Manage Tab."

from wherever you want, from commandline, buttons, toolpalettes,

 

>>"Before I start the process of writing the code, is this do-able please?"

I think the layer properties manager part wasn't very clear,
you should explain that in more detail.

 

It sounds you never programmed kin AutoCAD before

Sebastian

0 Likes
Message 3 of 10

cve60069
Advocate
Advocate

Thank you for the reply.  I am very versed in coding using VBA; its the Layer manager I am having trouble accessing.

 

I want to open a blank drawing and run a macro that will add my Layer Filters into the Layers manager (see snip).

 

Regards

 

Daniel

0 Likes
Message 4 of 10

Michiel.Valcke
Advisor
Advisor
Accepted solution

I refer to the datamodel:

MichielValcke_0-1680089811820.png

You can create your own layers in VBA without trouble : 
https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-14F28A52-81E5-4CD0-AA79-ADC09E91BB8C
You just need to grab the application, then document then layer collection


I don't think there's a way to create layer filters with vba, but it is easily done by lisp/macro or script by mimicking the command line input:
https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/script-or-lisp-to-create-layer-filte...


0 Likes
Message 5 of 10

cve60069
Advocate
Advocate

Thanks

 

Knew it could be done.  I need to learn a bit of Lisp.

 

Dan

0 Likes
Message 6 of 10

TomBeauford
Advisor
Advisor
Accepted solution

Example of ones we use in Civil 3D:

 

; (load "LayFilterAdd.lsp")
; ^C^C^P(or LayFilterAdd (load "LayFilterAdd.lsp"));(LayFilterAdd)
; [B][COLOR="#FF0000"]Newer versions automatically display Xref Layer Filters **Adding Xref Layer Filter names the same as them can cause serious issues**[/COLOR][/B]
; Save, close and reopen the DWT or DWG for the Filters to be put into alphabetical order.
(defun LayFilterAdd (/ collection names)
;  (load "LFD.lsp")
;  (command "C:LFD" "All*") *Layers
  (setq names (list ""))
  (if (not (vl-catch-all-error-p (setq collection (vl-catch-all-apply
    (function (lambda () (vla-item (vla-getextensiondictionary (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))) "ACAD_LAYERFILTERS")))
  ))))
;  (vlax-for item collection (setq names (cons (strcase (vla-get-name item)) names))))
  (vlax-for item collection (setq names (cons (vla-get-name item) names))))
  names 
  (or(member "CALC Points" names)(command "._-layer" "filter" "new" "property" "All" "NAME==\"V-NODE-CALC\" or NAME== \"Layer*\"" "CALC Points" "X" nil))
  (or(member "HATCH No xrefs" names)(command "._-layer" "filter" "new" "property" "All" "NAME==\"~*|*\" and NAME==\"*HATCH\"" "HATCH No xrefs" "X" nil))
  (or(member "Linetype" names)(command "._-layer" "filter" "new" "property" "All" "LINETYPE==\"~Continuous\"" "Linetype" "X" nil))
  (or(member "Lineweight" names)(command "._-layer" "filter" "new" "property" "All" "LINEWEIGHT==\"~Default\"" "Lineweight" "X" nil))
  (or(member "NCS" names)(command "._-layer" "filter" "new" "property" "All" "NAME==\"[A,C,E,L,V]-*\" or NAME== \"Layer*\"" "NCS" "X" nil))
  (or(member "NCS No xrefs" names)(command "._-layer" "filter" "new" "property" "All" "NAME==\"~*|*\" and NAME==\"[A,C,E,L,V]-*\" or NAME== \"Layer*\"" "NCS No xrefs" "X" nil))
  (or(member "No NCS" names)(command "._-layer" "filter" "new" "property" "All" "NAME==\"~[A,C,E,L,V]-*\"" "No NCS" "X" nil))
  (or(member "No NCS or xrefs" names)(command "._-layer" "filter" "new" "property" "All" "NAME==\"~*|*\" and NAME==\"~[A,C,E,L,V]-*\"" "No NCS or xrefs" "X" nil))
  (or(member "No NODE" names)(command "._-layer" "filter" "new" "property" "All" "NAME==\"~*|*\" and NAME==\"[A,C,E,L,V]-*\" and NAME==\"~*-NODE*\" or NAME== \"Layer*\"" "No NODE" "X" nil))
  (or(member "NODE" names)(command "._-layer" "filter" "new" "property" "All" "NAME==\"~*|*\" and NAME==\"[A,C,E,L,V]-*\" and NAME==\"*-NODE*\" or NAME== \"Layer*\"" "NODE" "X" nil))
  (or(member "Profile" names)(command "._-layer" "filter" "new" "property" "All" "NAME==\"C-ROAD-PROF*\" or NAME== \"Layer*\"" "Profile" "X" nil))
  (or(member "Sections" names)(command "._-layer" "filter" "new" "property" "All" "NAME==\"C-ROAD-SEC*\" or NAME== \"Layer*\"" "Sections" "X" nil))
  (or(member "Topo" names)(command "._-layer" "filter" "new" "property" "All" "NAME==\"C-TOPO*\" or NAME== \"Layer*\"" "Topo" "X" nil))
  (princ "Layer Filter Names » ")(princ names)
;  (princ "\nSave, close and reopen the DWT or DWG for the Filters to be put into alphabetical order.")
  (princ)
); function
(LayFilterAdd)

 

  Note: All recent AutoCAD versions & verticles automatically display Xref Layer Filters **Adding Xref Layer Filter names the same as them can cause serious issues**!

64bit AutoCAD Map & Civil 3D 2023
Architecture Engineering & Construction Collection
2023
Windows 10 Dell i7-12850HX 2.1 Ghz 12GB NVIDIA RTX A3000 12GB Graphics Adapter
0 Likes
Message 7 of 10

cadffm
Consultant
Consultant

You can also use command -LAYER, so you don't need lisp api ()

See beaufordts Code, no Lisp-API needed, just simple controle of the native -layer command is enough.

In VBA you are usinf sendcommand to do it.

(But of course,   in Lisp API you have also other wayS  to work with layerfilters)

Sebastian

Message 8 of 10

cve60069
Advocate
Advocate

Dear All

 

Thank you for the advice.  I am having to work on other work at the moment but I shall be returning to this topic when I start the code.  I will publish my results.

 

0 Likes
Message 9 of 10

cve60069
Advocate
Advocate

Dear  TomBeauford

 

Thanks for the code. It works perfectly and I am going to have very little work to make it work for my filters.  Brilliant.

0 Likes
Message 10 of 10

cve60069
Advocate
Advocate

Thanks for the link.  The code was perfect.

0 Likes