Hi All,
I am looking for a VBA code to select the blocks in drawing based on Block name (Arrow).
Similar to autolisp command "(sssetfirst nil (ssget "_X" '((0 . "INSERT") (2 . "Arrow"))))"
Please share me if any code available.
Thank you..
Regards,
Harish Kumar M
Solved! Go to Solution.
Solved by ed57gmc. Go to Solution.
Use the lisp expression as stupid commandline-input (AutoCAD understand lisp expressions directly from the commandline),
use SENDCOMMAND to fire the input to the commandline // quick and dirty solution, because in VBA is nothing similar to ssget available.
Or you have to programm what you need, iterate thru the space(s) you want, check every item
for type, if blockreference check it for effectivename and if the effectivename match what you are
searching for, add the item to a selectionset.
Sorry.
Sebastian
You can get a SelectionSet of block references using the code below. Call using GetSS_BlockName("Arrow")
Public Function AddSelectionSet(SetName As String) As AcadSelectionSet ' This routine does the error trapping neccessary for when you want to create a ' selectin set. It takes the proposed name and either adds it to the selectionsets ' collection or sets it. On Error Resume Next Set AddSelectionSet = ThisDrawing.SelectionSets.Add(SetName) If Err.Number <> 0 Then Set AddSelectionSet = ThisDrawing.SelectionSets.Item(SetName) AddSelectionSet.Clear End If End Function Public Function GetSS_BlockName(BlockName As String) As AcadSelectionSet 'creates a ss of blocks with the name supplied in the argument Dim s2 As AcadSelectionSet Set s2 = AddSelectionSet("ssBlocks") ' create ss with a name s2.Clear ' clear the set Dim intFtyp(3) As Integer ' setup for the filter Dim varFval(3) As Variant Dim varFilter1, varFilter2 As Variant intFtyp(0) = -4: varFval(0) = "<AND" intFtyp(1) = 0: varFval(1) = "INSERT" ' get only blocks intFtyp(2) = 2: varFval(2) = BlockName ' whose name is specified in argument intFtyp(3) = -4: varFval(3) = "AND>" varFilter1 = intFtyp: varFilter2 = varFval s2.Select acSelectionSetAll, , , varFilter1, varFilter2 ' do it Set GetSS_BlockName = s2 End Function
BTW, The AutoCAD VBA forum is over here.
Hi,
Thank you for your reply..
I tried sending ssget by command line, but i am getting the error shown below. Please suggest
Thank you..
Harish
The SendCommmand method takes an argument that evaluates to a single String argument. You've got multiple double quotes. You need to use the backslash to tell vba that they're literal characters. However, you won't be able to use SendCommand that way because it is asyncronous. The SendCommand method waits until all the vba is processed and then it sends the string to the command line AFTER the vba is through. Use the vba functions I gave you.
Hi,
I need to send around series of 63 AutoCAD command via VBA to execute a single task (like AutoCAD script), in which there are requirement to select blocks by its name in between. So i am looking for VBA SEND COMMAND code to simulate "ssget".
Please suggest how to incorporate "(sssetfirst nil (ssget "_X" '((0 . "INSERT") (2 . "Arrow"))))" in VBA.
Thank you..
Regards,
Harish
Why do you need to use SendCommand? Its not a very good way to do things. The code I sent you previously creates a selection set just like ssget does.
Your script has some logic problems. The ssget will find all blocks called "arrow". Your script will only process the first one. Is that what you want?
Exactly.. In Layout PSPACE I have only one block called "arrow", which needs to be selected and rotate at its position by give angle value. For which I am using "ssget" to select that block. Also I am not find any other way to select the block by name in AutoCAD command lines.
Please share me if you have any other idea to execute this..
Thank you..
Harish
Using the functions I gave you earlier...
Dim ss As AcadSelectionSet Set ss = GetSS_BlockName("Arrow") If ss.Count > 0 Then Dim oBlock As AcadBlockReference Set oBlock = ss.Item(0) With oBlock .InsertionPoint = (23.0, 2.3, 0) .Rotation = 340
.Update End With End If
Can't find what you're looking for? Ask the community or share your knowledge.