Author Topic: insert DynamicBlock  (Read 3887 times)

0 Members and 1 Guest are viewing this topic.

Humbertogo

  • Guest
insert DynamicBlock
« on: January 18, 2008, 04:17:52 AM »
How to insert DynamicBlock using vba

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: insert DynamicBlock
« Reply #1 on: January 18, 2008, 04:20:20 AM »

what have you tried ?
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Humbertogo

  • Guest
Re: insert DynamicBlock
« Reply #2 on: January 18, 2008, 05:26:37 AM »
i have 2 kind of blocks
dynamic block that have save in the current Drawing and the another that have save a s block with a name
i try to insert <current Drawing>  DB

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: insert DynamicBlock
« Reply #3 on: April 09, 2008, 11:46:42 AM »
what have you tried ?
I have tried obj.Visibility="String" but that didn't work.  When I grab a DB and look at the properties, I see in the custom area the Visibility option.  I was hoping to use that, but VBA choked
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

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: insert DynamicBlock
« Reply #4 on: April 09, 2008, 11:52:45 AM »
I found this part in the help file, but I haven't figured out how to make it work
Code: [Select]
      objSelSet.SelectOnScreen
      For Each obj In objSelSet
            Dim dbP As AcadDynamicBlockReferenceProperty
            Set dbP = obj.GetDynamicBlockProperties
            dbP.Value = "Switch"
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

Murph

  • Bull Frog
  • Posts: 402
  • P.I.T.A.
Re: insert DynamicBlock
« Reply #5 on: April 09, 2008, 01:51:58 PM »
I got this from doing a search on the Autodesk forums.
Here is the link to the original thread
http://discussion.autodesk.com/thread.jspa?messageID=5610807

Code: [Select]
Private Sub ScanBlks()
Dim dybprop As Variant, i As Integer
Dim bobj As AcadEntity
For Each bobj In ThisDrawing.ModelSpace
If bobj.ObjectName = "AcDbBlockReference" Then
If bobj.IsDynamicBlock Then
If bobj.EffectiveName = "cirtagleader" Then
dybprop = bobj.GetDynamicBlockProperties
For i = LBound(dybprop) To UBound(dybprop)
If dybprop(i).PropertyName = "Visibility" Then
dybprop(i).Value = "Leader Off"
End If
Next i
End If
End If
End If
Next

End Sub

The portion of the code you'd be interested in is

If dybprop(i).PropertyName = "Visibility" Then
dybprop(i).Value = "Leader Off"
End If
Murphy's Law applies to all.
Whatever can go wrong, will, and at the most inopportune time.

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: insert DynamicBlock
« Reply #6 on: April 09, 2008, 02:03:45 PM »
Thanks Murph, I missed that one in my search.  I guess I should broaden my search criteria a little.

BTW, it works perfectly
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

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: insert DynamicBlock
« Reply #7 on: April 09, 2008, 02:07:11 PM »
Now, to work up a routine to insert and switch based on passed argument
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

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: insert DynamicBlock
« Reply #8 on: April 09, 2008, 02:58:49 PM »
well crap, I made it work, but Annotative blocks dont seem to work
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

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: insert DynamicBlock
« Reply #9 on: April 10, 2008, 11:19:13 AM »
OK, now im just mad.  I got a pretty good idea of how to make this somewhat work, and now the CUI is killing me.
Code: [Select]
vbastmt
insblk "c:\symbols\S-SCHM-SWCH.DWG", "Test Link"
works perfectly from command line but the \ takes a dive in the CUI.  Any gurus out there know a way around this?
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

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: insert DynamicBlock
« Reply #10 on: April 10, 2008, 11:19:52 AM »
here is the accompanying code
Code: [Select]
Public Sub insblk(blkname As String, strLayer As String, Optional strVisibilityState As String)
      Dim blkr As AcadBlockReference
      Dim inspt As Variant
      Dim strCurrentLayer As AcadLayer, newLayer As AcadLayer
      Dim dybprop As Variant, i As Integer
      inspt = ThisDrawing.Utility.GetPoint(, "Enter a point: ")
      Set strCurrentLayer = ThisDrawing.ActiveLayer
      Set newLayer = ThisDrawing.Layers.Add(strLayer)
      ThisDrawing.ActiveLayer = newLayer
      Set blkr = ThisDrawing.ModelSpace.InsertBlock(inspt, blkname, 1, 1, 1, 0)
      If blkr.IsDynamicBlock Then
            dybprop = blkr.GetDynamicBlockProperties
            For i = LBound(dybprop) To UBound(dybprop)
                  If dybprop(i).PropertyName = "Visibility" Then
                        dybprop(i).Value = strVisibilityState
                  End If
            Next i
      End If
      ThisDrawing.ActiveLayer = strCurrentLayer
End Sub
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

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: insert DynamicBlock
« Reply #11 on: April 10, 2008, 12:57:09 PM »
and to make matters worse, that stupid vbastmt gives me a syntax err if any dvb is loaded besides the one Im calling the sub from.  Any idea why this thing is being a PITA?
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

Guest

  • Guest
Re: insert DynamicBlock
« Reply #12 on: April 10, 2008, 01:45:25 PM »
I use the following to load/run modules from different DVBs.

Code: [Select]
(defun DVBLoader (strDVBName strDVBModule / )
   (command "-vbarun" (strcat strDVBName "!" strDVBModule))
   (princ)
)

^C^C^P(load" VBA-Apps");(DVBLoader "PrintManager.dvb" "modMain.Main");

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: insert DynamicBlock
« Reply #13 on: April 10, 2008, 01:58:22 PM »
Hey Matt, how about passing arguments to the dvb though?  thats what is killing me
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

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: insert DynamicBlock
« Reply #14 on: April 28, 2008, 12:41:27 PM »
ok, now im really stuck.  it seems that i cant pass an argument to a dvb from LISP or from a macro w/i the CUI.  Any ideas?  What i dont want to do is make tons of 3 line lisp codes just to insert a stupid DynBlock
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