TheSwamp

Code Red => VB(A) => Topic started by: Humbertogo on January 18, 2008, 04:17:52 AM

Title: insert DynamicBlock
Post by: Humbertogo on January 18, 2008, 04:17:52 AM
How to insert DynamicBlock using vba
Title: Re: insert DynamicBlock
Post by: Kerry on January 18, 2008, 04:20:20 AM

what have you tried ?
Title: Re: insert DynamicBlock
Post by: Humbertogo 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
Title: Re: insert DynamicBlock
Post by: CmdrDuh 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
Title: Re: insert DynamicBlock
Post by: CmdrDuh 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"
Title: Re: insert DynamicBlock
Post by: Murph 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 (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
Title: Re: insert DynamicBlock
Post by: CmdrDuh 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
Title: Re: insert DynamicBlock
Post by: CmdrDuh on April 09, 2008, 02:07:11 PM
Now, to work up a routine to insert and switch based on passed argument
Title: Re: insert DynamicBlock
Post by: CmdrDuh on April 09, 2008, 02:58:49 PM
well crap, I made it work, but Annotative blocks dont seem to work
Title: Re: insert DynamicBlock
Post by: CmdrDuh 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?
Title: Re: insert DynamicBlock
Post by: CmdrDuh 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
Title: Re: insert DynamicBlock
Post by: CmdrDuh 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?
Title: Re: insert DynamicBlock
Post by: Guest 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");
Title: Re: insert DynamicBlock
Post by: CmdrDuh on April 10, 2008, 01:58:22 PM
Hey Matt, how about passing arguments to the dvb though?  thats what is killing me
Title: Re: insert DynamicBlock
Post by: CmdrDuh 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
Title: Re: insert DynamicBlock
Post by: Guest on April 28, 2008, 01:00:08 PM
What about setting the USERS1-5 variables from the macro and have the DVB read the variables?


blkName = ThisDrawing.GetVariable("USERS1")
strLayer = ThisDrawing.GetVariable("USERS2")
strVisibilityState = ThisDrawing.GetVariable("USERS3")
Title: Re: insert DynamicBlock
Post by: CmdrDuh on April 28, 2008, 01:19:50 PM
so your suggesting (like the way i start this? haha) that i use a macro to pass arguments to lisp, (or set them directly from the cui) and then have the DVB read the users# settings?  Seems like a very round about way to get there.  I may have to go that route, but i thought there has to be a way to make this work.  I would even settle for a LISP version at this point.  If anybody knows how to set the visibility of a block w/ lisp, that would solve the problem as well.
Title: Re: insert DynamicBlock
Post by: Guest on April 28, 2008, 01:32:06 PM
If anybody knows how to set the visibility of a block w/ lisp, that would solve the problem as well.

http://www.theswamp.org/index.php?topic=21648.msg261969#msg261969
Title: Re: insert DynamicBlock
Post by: CmdrDuh on April 28, 2008, 02:26:21 PM
Thanks Matt, that works perfectly.
Title: Re: insert DynamicBlock
Post by: Guest on April 28, 2008, 03:00:19 PM
Thanks Matt, that works perfectly.

 :kewl: