.NET

Reply
New Member
truss85
Posts: 2
Registered: ‎02-23-2011
Message 1 of 6 (259 Views)

Can not write selected block attributes

259 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


 

Active Contributor
cincir
Posts: 32
Registered: ‎08-12-2011
Message 2 of 6 (248 Views)

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.

Mentor
truss_85
Posts: 173
Registered: ‎02-13-2011
Message 3 of 6 (235 Views)

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.

 

 

Valued Mentor
gasty1001
Posts: 438
Registered: ‎04-11-2010
Message 4 of 6 (224 Views)

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

 

Mentor
truss_85
Posts: 173
Registered: ‎02-13-2011
Message 5 of 6 (207 Views)

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

Active Contributor
cincir
Posts: 32
Registered: ‎08-12-2011
Message 6 of 6 (197 Views)

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 .

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community