Author Topic: LISP, AutoScript, Anything to copy a selection set into a new dwg  (Read 1333 times)

0 Members and 1 Guest are viewing this topic.

Offline dopefishTopic starter

  • Senior Member
  • ****
  • Posts: 375
  • Country: us
  • Gender: Male
Like the title says, does anyone have or know of a method to take a selection set of object and copy them to a new drawing?
"And the wood header is still 4  3/4" on top of the top of the double top plate." . . . Random VDC Coodinator

I love coordination

Offline Darren Young

  • Premier Member
  • *****
  • Posts: 2064
  • Country: us
  • Gender: Male
    • BIM There Done That.
Re: LISP, AutoScript, Anything to copy a selection set into a new dwg
« Reply #1 on: Apr 19, 2023, 18:52:17 PM »
It can be done in Lisp. But it's literally been a couple decades since I've done it.  There's a few hoops to jump through but you're essentially launching a headless AutoCAD and loading a document into it and manipulating that.

Because there's no UI, there is no selection sets which use graphics to select things. So you can only "get" a selection set in the document that you're in.  Writing all those entities back on by one would be how you'd have to do it and that's going to be a pain given the diversity of entity types.

You're better off making the selection a block, and sending the block to the other document than exploding it...which might or might not be possible.

And if you're talking CADmep...I'm not sure that headless session would run the ARX. It might...there's a few other things I know that are doing that but that's a different thing that launching the full blown app with visibility turned off.

Depending on your need....I'd litterally find just about any other way to do this.

Lisp runs in the Document's namespace which is what makes doc to doc harder in Lisp.

VB, VBA, VB.Net, C++(Arx), or C# are better suited from a tech standpoint to do this IMO.

There's a few other workaround you could do to like have one doc export to a temp DWG/Block on dis and have some sort of reactor/timed even in another doc that looks for a semaphore file, flag or other mutex that allows the other document to know there's something waiting to act upon and bring it in.

These types of coding tasks are really more fun/challenging than they are practical unless there's a strong need.

And then there's the poor man's version, using a tool Like AutoTable to build a macro that performs these actions for you like you would with a mouse/keyboard.   Likely be the easiest approach even if not very eligant or refined.

Offline dopefishTopic starter

  • Senior Member
  • ****
  • Posts: 375
  • Country: us
  • Gender: Male
Re: LISP, AutoScript, Anything to copy a selection set into a new dwg
« Reply #2 on: Apr 23, 2023, 16:00:54 PM »
Thank you for that reply Darren. The namespace issue is exactly what I was up against. I have elected to go a different route and rather than fighting the namespace issue to just go with it. SAVE, SAVEAS, ERASE everything not my selection set, insert some titleblocks and place some addreports, and lastly OPEN the original drawing. crude but works for now until I can finally get an addin written.
"And the wood header is still 4  3/4" on top of the top of the double top plate." . . . Random VDC Coodinator

I love coordination

Offline Darren Young

  • Premier Member
  • *****
  • Posts: 2064
  • Country: us
  • Gender: Male
    • BIM There Done That.
Re: LISP, AutoScript, Anything to copy a selection set into a new dwg
« Reply #3 on: Apr 24, 2023, 14:47:46 PM »
Well, if you're going to go that route....

You can have a Lisp Load in ALL DWGs.

You can also have your ACAD.LSP or ACADDOC.LSP run code that looks for clues (file on disk, registry entry) that tells it where in your multiple document process you are and pickup where it left off.

It can even write a script file to execute as well. So the script does the multi-doc processing (open/save/close).

The script can also load the Lisp code to get around the namespace issue. But might be best to make sure you're in Single Document mode vs Multi-Document mode.

These types of tasks are more fun (provided you like troubleshooting). However, you often end up with something elegantly crude and robustly fragile.