Author Topic: Partially inserting a dwg with VBA  (Read 3180 times)

0 Members and 1 Guest are viewing this topic.

Matersammichman

  • Guest
Partially inserting a dwg with VBA
« on: June 21, 2006, 07:18:59 AM »
I usually partially insert a dwg with all of my layering info into a dwg with a macro, then cancel out. This prevents the dwg from having any dwg entities while gaining all of the layering data. My macro code goes like this:

^C^C_-i;whatever.dwg;^C^C^C^C_-purge;b;;n;^C^C_-purge;b;;n;^C^C_-purge;b;;n;^C^C_qsave ^M;

I want to perform the same task in VBA, but haven't been able to code it to do the partial dwg install.

Help?...please.

hendie

  • Guest
Re: Partially inserting a dwg with VBA
« Reply #1 on: June 21, 2006, 08:20:16 AM »
why bother inserting a drawing, just write a vba app to create the necessary layers

Matersammichman

  • Guest
Re: Partially inserting a dwg with VBA
« Reply #2 on: June 21, 2006, 08:36:17 AM »
Because to re-write all of my layering, colors, linetypes, plot/noplot, etc... for all of my AEC disciplines would take the better part of a day.

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Partially inserting a dwg with VBA
« Reply #3 on: June 21, 2006, 09:57:13 AM »
You can also insert an empty with only layers in it and then delete the blockref.
Then Delete the block (delete all the ents in the block first).
As far as your layers taking a day. You could make a txt file with all the layer info in it (A couple of minutes code) then read that.

Glenn R

  • Guest
Re: Partially inserting a dwg with VBA
« Reply #4 on: June 22, 2006, 09:04:10 PM »
Clone from drawing to another:

Code: [Select]
Public Sub CloneLayers()
    Dim pAxDoc As AxDbDocument
    ' Create an instance...
    Set pAxDoc = New AxDbDocument
    ' Load in the drawing containg the layers...
    pAxDoc.Open "C:\Temp\CloneLayersTest.dwg"
   
    ' Delcare an object array to hold the layers...
    Dim pLayersToClone() As AcadLayer
    Dim i As Integer
    Dim pAxLayer As AcadLayer
   
    i = -1
    For Each pAxLayer In pAxDoc.Layers
        i = i + 1
        ReDim Preserve pLayersToClone(i)
        Set pLayersToClone(i) = pAxLayer
    Next
   
    ' Clone 'em!
    pAxDoc.CopyObjects pLayersToClone, ThisDrawing.Layers
   
    ' Clean up
    Set pAxDoc = Nothing
End Sub

Make sure to set a reference to AutoCAD/ObjectDBX Common 16.0 type library.


Cheers,
Glenn.

Matersammichman

  • Guest
Re: Partially inserting a dwg with VBA
« Reply #5 on: June 23, 2006, 07:08:53 AM »
Thanks for the code Glenn!
Bryco, I ended up using your advice, thanks!

Bob Wahr

  • Guest
Re: Partially inserting a dwg with VBA
« Reply #6 on: June 23, 2006, 12:41:55 PM »
Brilliant Glenn.  Thanks a ton.  I've been looking for a way to do a PSETUPIN programatically for a long time and had given up on it.  This works beautifully.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4076
Re: Partially inserting a dwg with VBA
« Reply #7 on: June 23, 2006, 03:15:17 PM »
so how are you doing the psetupin Bob?
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Bob Wahr

  • Guest
Re: Partially inserting a dwg with VBA
« Reply #8 on: June 23, 2006, 04:13:30 PM »
Currently with the import button in page setup.  With this, I will do it something like this
Code: [Select]
Public Sub CloneSetups()
    Dim pAxDoc As AxDbDocument
    ' Create an instance...
    Set pAxDoc = New AxDbDocument
    ' Load in the drawing containg the layers...
    pAxDoc.Open "p:\acad2k6\satblk\SNA-AZTU-PAGESETUPS.dwg"
   
    ' Delcare an object array to hold the layers...
    Dim pSetToClone() As AcadPlotConfiguration
    Dim i As Integer
    Dim pAxPSet As AcadPlotConfiguration
   
    i = -1
    For Each pAxPSet In pAxDoc.PlotConfigurations
        i = i + 1
        ReDim Preserve pSetToClone(i)
        Set pSetToClone(i) = pAxPSet
    Next
   
    ' Clone 'em!
    pAxDoc.CopyObjects pSetToClone, ThisDrawing.PlotConfigurations
   
    ' Clean up
    Set pAxDoc = Nothing
End Sub
The above, obviously, was a quick edit of Glenn's sub to test and see if it will work, it does.  I will probably rename some things to fit my conventions but it's outstanding.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4076
Re: Partially inserting a dwg with VBA
« Reply #9 on: June 23, 2006, 04:27:55 PM »
I was going to do the same, but you beat me to it.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Glenn R

  • Guest
Re: Partially inserting a dwg with VBA
« Reply #10 on: June 26, 2006, 01:02:53 AM »
You're welcome Bob and in fact I have had the same thing (importing pagesetups) running for a couple of years.

There is one gotcha though. Pagesetups are implemented as dictionary objects and as such, if you clone from one drawing to another, the new dictionary entry gets an anonymous name, however the pagesetup Name (that appears in the pagesetup dialog) is preserved.

What this means, is that if you were to run your code to import pagesetups twice in a row on the same drawing, then fire up the pagesetup's dialog, you will see duplicates appearing. I delete all pagesetups before i import as a safety measure.

There is a better way to do this with C# but deleting first is ok. I can explain more if there is a need.

Bob Wahr

  • Guest
Re: Partially inserting a dwg with VBA
« Reply #11 on: June 26, 2006, 11:10:22 AM »
Thanks for the tip, definitely goog to know.  When I start diving into C#, which will be as soon as I can find time, I might hit you up on the better way.