Hi Everybody,
I have a prblem with the code. I posted the code below. I have two questions about the code.
The First in vba there is a function refers to blocks effective name is there ant similar function vb.net has?
Because when I filtered Blocks that I want particularly DYNBlocks I get all of them in vba I inserted
İf blockobject.effectivename=" ..." then
it can solved. but invb.net I did not find a way to get rid of this...
The second question is the code can not able to write attribute when selecting fence mode. In normal selection it did not happen. What am I doing wrong?
Thanks for replies...
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.Runtime
Public Class Class1
<CommandMethod("gss")> _
Public Sub gget()
Dim acDocEd As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim entOpt As PromptEntityOptions = New PromptEntityOptions("select a polyline:")
entOpt.AllowNone = True
Dim spoly As PromptEntityResult = acDocEd.GetEntity(entOpt)
Dim acCurDb As Database = Application.DocumentManager.MdiActiveDocument.Database
Using acTrans1 As Transaction = acCurDb.TransactionManager.StartTransaction()
Dim obj As DBObject = acTrans1.GetObject(spoly.ObjectId, OpenMode.ForWrite)
If TypeOf (obj) Is Polyline Then
Dim poly As Polyline = CType(obj, Polyline)
Dim opt As New Point3d
Dim sel_fence As New Autodesk.AutoCAD.Geometry.Point3dCollection
For ii = 0 To poly.NumberOfVertices - 1
opt = poly.GetPoint3dAt(ii)
sel_fence.Add(opt)
Next
Dim acTypValAr(0) As TypedValue
acTypValAr(0) = New TypedValue(Autodesk.AutoCAD.DatabaseServices.DxfCode.BlockName, "MET-HVZ2,`*U*")
Dim acSelFtr As SelectionFilter = New SelectionFilter(acTypValAr)
Dim sblck As PromptSelectionResult = acDocEd.SelectFence(sel_fence, acSelFtr)
If sblck.Status = PromptStatus.OK Then
Dim acSSet As SelectionSet = sblck.Value
Dim nnstr As String
Dim nn As Integer
nn = 1
For Each acSSObj As SelectedObject In acSSet
Dim acEnt As Entity = acTrans1.GetObject(acSSObj.ObjectId, OpenMode.ForWrite)
nnstr = "H" & nn.ToString
SetAttribute(acSSObj.ObjectId, "HIDRANT_ISIM", nnstr)
nn = nn + 1
Next
acDocEd.WriteMessage("Number of objects selected: " & acSSet.Count.ToString())
Else
acDocEd.WriteMessage("Number of objects selected: 0")
End If
Else
acDocEd.WriteMessage("Selection must be a polyline...")
End If
End Using
End Sub
all the block objects are BlockReference objects those reference to a BlockTableRecord objects in BlockTable. BlockReference objects have IsDynamicBlock , DynamicBlockTableRecord and BlockTableRecord properties. you can check if a BlockReference is pointing to a DynamicBlock or not via IsDynamicBlock property. this property returns true or false. after you determine the type you can obtain ObjectId of the BlockTableRecord via DynamicBlockTableRecord or BlockTableRecord. and if you open BlockTableRecord you can obtain its name via its Name property. Also the Name property of BlockReference object returns the name of the BlockTableRecord it references to.
Hope that helps.
Firdt of all thanks for the answer;
But it is not a solution. Let say I have two different dynamic block in the selection set both name return to "`*U*".
You Know that a dynamic block if it is dynamic properties not set default block.name property returns "`*U*" also
IsDynamicBlock property returns block is dynamic or can not give a clue about block name always returns "`*U*".
If you take a look to selection filter, you had seen I filtered all the dynamic blocks already.
I want effective name to get rid of that or any other way excepted. I hope I represent my problem clearly.
Hi,
If you want to filter dynamic blocks, i think it's better to select just generic "INSERT" and then to check if is dynamic and it have the name you want , like this:
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction() Dim acTypValAr(0) As TypedValue acTypValAr.SetValue(New TypedValue(DxfCode.Start, "INSERT"), 0) Dim acSelFtr As SelectionFilter = New SelectionFilter(acTypValAr) Dim acSSPrompt As PromptSelectionResult acSSPrompt = ed.SelectAll(acSelFtr) If acSSPrompt.Status = PromptStatus.OK Then Dim acSSet As SelectionSet = acSSPrompt.Value For Each acSSObj As SelectedObject In acSSet Dim blkref As BlockReference = acSSObj.ObjectId.GetObject(OpenMode.ForRead) If blkref.IsDynamicBlock Then Dim btr As BlockTableRecord btr = acTrans.GetObject(blkref.DynamicBlockTableRecord, OpenMode.ForRead) If btr.Name="MyBlockName" then .... End If .... Next ... End If ... End Using
Hope this help you.
Gaston Nunez
Thanks gusty1001 it worked.
I also ove an appology to cincer I can not understand
what you are saying...
Anyway thanks to both of you...
Can't find what you're looking for? Ask the community or share your knowledge.