TheSwamp
Code Red => VB(A) => Topic started by: Humbertogo on January 18, 2008, 04:17:52 AM
-
How to insert DynamicBlock using vba
-
what have you tried ?
-
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
-
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
-
I found this part in the help file, but I haven't figured out how to make it work
objSelSet.SelectOnScreen
For Each obj In objSelSet
Dim dbP As AcadDynamicBlockReferenceProperty
Set dbP = obj.GetDynamicBlockProperties
dbP.Value = "Switch"
-
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)
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
-
Thanks Murph, I missed that one in my search. I guess I should broaden my search criteria a little.
BTW, it works perfectly
-
Now, to work up a routine to insert and switch based on passed argument
-
well crap, I made it work, but Annotative blocks dont seem to work
-
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.
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?
-
here is the accompanying code
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
-
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?
-
I use the following to load/run modules from different DVBs.
(defun DVBLoader (strDVBName strDVBModule / )
(command "-vbarun" (strcat strDVBName "!" strDVBModule))
(princ)
)
^C^C^P(load" VBA-Apps");(DVBLoader "PrintManager.dvb" "modMain.Main");
-
Hey Matt, how about passing arguments to the dvb though? thats what is killing me
-
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
-
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")
-
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.
-
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
-
Thanks Matt, that works perfectly.
-
Thanks Matt, that works perfectly.
:kewl: