• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    New Member
    truss85
    Posts: 2
    Registered: ‎02-23-2011

    Can not write selected block attributes

    197 Views, 5 Replies
    01-15-2012 01:27 PM

    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


     

    Please use plain text.
    Active Contributor
    cincir
    Posts: 32
    Registered: ‎08-12-2011

    Re: Can not write selected block attributes

    01-15-2012 08:10 PM in reply to: truss85

    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.

    Please use plain text.
    Distinguished Contributor
    truss_85
    Posts: 131
    Registered: ‎02-13-2011

    Re: Can not write selected block attributes

    01-16-2012 04:16 AM in reply to: cincir

    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.

     

     

    Please use plain text.
    Mentor
    Posts: 223
    Registered: ‎04-11-2010

    Re: Can not write selected block attributes

    01-16-2012 06:20 AM in reply to: truss85

    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

     

    Please use plain text.
    Distinguished Contributor
    truss_85
    Posts: 131
    Registered: ‎02-13-2011

    Re: Can not write selected block attributes

    01-16-2012 10:34 AM in reply to: gasty1001

    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...

    Please use plain text.
    Active Contributor
    cincir
    Posts: 32
    Registered: ‎08-12-2011

    Re: Can not write selected block attributes

    01-16-2012 01:53 PM in reply to: truss_85

    No appologies needed. happy that helps solve your problem. maybe it was better to show code .

    Please use plain text.