Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Import Layer LISP

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
Anonymous
4825 Views, 11 Replies

Import Layer LISP

Hey Guys,

 

I'm trying to set up an easy way to import layers from a certain dwt. file with a shortcut.

 

Now I found this code, which kind of works, but doesn't do the whole trick. It works with a Popup where I have to insert the dwt. file. It's also annoying that it opens this file than and I have to close it manually.

I would like to have this without any importoptions and automatically takes this one file always for the layers.

 

My file would be located here:

"I:\AutoCAD Blöcke\Template\__Bürostandard"

 

 

(defun c:IL (/ oAcad oCurDoc strFile oOpenDoc oOpenDocLayers lstObj oLayer array)
  (setq oAcad (vlax-get-acad-object))
  (setq oCurDoc (vla-get-ActiveDocument oAcad))

  (setq strFile (getfiled "choose file:" (getvar "DWGPREFIX") "dwt" 0))
  (setq oOpenDoc (vla-Open (vla-get-documents oAcad) strFile))
  (setq oOpenDocLayers (vla-get-layers oOpenDoc))
  (setq lstObj nil) 
  (vlax-for oLayer oOpenDocLayers (setq lstObj (cons oLayer lstObj)))

  (setq array (vlax-make-safearray vlax-vbObject (cons 0 (1- (length lstObj)))))
  (vlax-safearray-fill array lstObj)

  (vla-CopyObjects oOpenDoc (vlax-make-variant array) (vla-get-Layers oCurDoc))

  (princ)
)

 

 

I would be really thankful, if anybody could help me with this issue, cause I'm new to this LISP stuff any can't modify it on my own. Smiley Happy

 

Thanks,

Klingi

11 REPLIES 11
Message 2 of 12
Lee_Mac
in reply to: Anonymous

Consider my Steal from Drawing program, also available at the Exchange App Store.

 

Be sure to read the documentation for the program which explains how to configure the function to automatically import layers (and other objects) from a predetermined location, such as a template.

 

Ask if you have any questions! Smiley Happy

 

Lee

Message 3 of 12
Lee_Mac
in reply to: Lee_Mac

For you case, you could create a custom command to call the Steal function in the following way:

 

(defun c:mysteal ( )
    (Steal "I:\\AutoCAD Blöcke\\Template\\__Bürostandard.dwt" '(("Layers" ("*"))))
)

 The above will attempt to import all layers from the drawing: "I:\\AutoCAD Blöcke\\Template\\__Bürostandard.dwt"

Message 4 of 12
Anonymous
in reply to: Lee_Mac

Thx Lee,

 

you did it again. Smiley Wink

saves me a lot of time and does exactly what it should and also my custom command works. was looking for that for a long time already. Smiley Happy

 

cheers Klingi

Message 5 of 12
Lee_Mac
in reply to: Anonymous

You're most welcome Klingi - I'm delighted that you like the program! Smiley Happy

 

Be sure to explore the full program, as it can import many more items than just layers Smiley Wink

 

Lee

Message 6 of 12
yoongFLLVC
in reply to: Lee_Mac

I tried your the plugin recently specifically for the layer states.  However it did not work for me.  I am wondering if it has something to do with new layers that were introduced in some of the nested xrefs.  The only other thing that I tried is the UCS import which worked for me.

 

Also, I suspect after installing your plugin, it possibly changed one of ACAD's setting or something like that somewhere.  The reason is that I have a separate lisp that i had no problem running before and all of the sudden stopped working.  The lisp is fine as it still works on other users within the office.  And between the time it worked/not working, the only change that I did to my ACAD is installing your plugin.  I am attaching the lisp file for your reference.  The lisp when added to the Startup Suite, will automatically etransmit and name any drawings that we open.

Message 7 of 12
Crass
in reply to: Lee_Mac

I know this is an old post, but I am wondering if the way to make this work is to create an additional lsp (defun c:mysteal) to call up the Steal lsp.

 

Or... can I just build that code into my toolpallete command such as:

^C^C_steal (Steal "C:\template.dwt" '(("Layers" ("*"))))

 

Note, this doesn't work for me. It just calls up the Steal lsp but I was hoping there was a way to automate the layer portion.

 

Can someone clarify? Thank you.

-----
AutoCAD 2018/2021
AutoCAD Civil 3D 2021
Message 8 of 12
dlanorh
in reply to: Crass


@Crass wrote:

I know this is an old post, but I am wondering if the way to make this work is to create an additional lsp (defun c:mysteal) to call up the Steal lsp.

 

Or... can I just build that code into my toolpallete command such as:

^C^C_steal (Steal "C:\template.dwt" '(("Layers" ("*"))))

 

Note, this doesn't work for me. It just calls up the Steal lsp but I was hoping there was a way to automate the layer portion.

 

Can someone clarify? Thank you.


That should probable be

 

^C^C_steal (Steal "C:\\template.dwt" '(("Layers" ("*"))))

or

^C^C_steal (Steal "C:/template.dwt" '(("Layers" ("*"))))

 

Look at post 3 and how the file string is constructed

I am not one of the robots you're looking for

Message 9 of 12
Crass
in reply to: dlanorh

Thanks for the reply. I guess that is my question. I am wondering how to activate the command. I tried entering Lee's file string in my tool palette command string but am not sure how to make this work. It doesn't even seem like the command string allows for multiple lines of text.


That should probable be

 

^C^C_steal (Steal "C:\\template.dwt" '(("Layers" ("*"))))

or

^C^C_steal (Steal "C:/template.dwt" '(("Layers" ("*"))))

 

Look at post 3 and how the file string is constructed


 

I made the correction as you suggested but now my tool buttom just executes the Steal lisp. It doesn't carry out the layer import.

 

Thanks

-----
AutoCAD 2018/2021
AutoCAD Civil 3D 2021
Message 10 of 12
Crass
in reply to: Lee_Mac

Hi Lee - I am struggling with figuring out where exactly to enter the function arguments. I apologize for my ignorance on this. My goal is to create a number of tool pallete buttons. For example:

  • Steal all layers from a template drawing
  • Steal all styles
  • Steal all page setups

..., etc.

 

I just don't understand to run these through a tool palette command string. Or do I need to create separate discrete lsp files for each of these functions. A little guidance on this would be really helpful. Thank you!

-----
AutoCAD 2018/2021
AutoCAD Civil 3D 2021
Message 11 of 12
Sea-Haven
in reply to: Crass

Lee will answer how to use his program correctly but a suggestion this way you do not need to preload the steal lisp program.

 

^c^c(if (not steal)(Load "StealV1-6.lsp"))(steal ............)

 

 

Message 12 of 12
Crass
in reply to: Sea-Haven

Thanks for the reply.


@Sea-Haven wrote:

 

^c^c(if (not steal)(Load "StealV1-6.lsp"))(steal ............)


So this command will load the Steal lsp if the application is not already loaded or in the startup suite? This is useful. Thanks.

 

-----
AutoCAD 2018/2021
AutoCAD Civil 3D 2021

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost