.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

CHANGE COLOR OF TEXT WITHIN A BLOCK

2 REPLIES 2
Reply
Message 1 of 3
bobmc
531 Views, 2 Replies

CHANGE COLOR OF TEXT WITHIN A BLOCK

We have 600 blocks with text in them and the text is presently set to color by layer.  Each block has a unique name.  All have an 08 and a 20 plain text entity within them, which are part of a dynamic visibility parameter.  We want to change the 08 to cyan (index color 4) and the 20 to magenta (index color 6).  We want to change them without having to open every block in the block editor.  This is only my second VB.NET program, and I am stuck.  Here's the code so far:

 

        <CommandMethod("PCC")> _
        Public Sub PCC()
            Dim myDB As DatabaseServices.Database
            Dim myDWG As ApplicationServices.Document
            Dim myEd As EditorInput.Editor
            Dim myTransMan As DatabaseServices.TransactionManager
            Dim myTrans As DatabaseServices.Transaction
            Dim myPSR As EditorInput.PromptSelectionResult
            Dim MySS As EditorInput.SelectionSet
            Dim myAcadEnt As DatabaseServices.Entity
            Dim PlantCode As DBText
            Dim myObjIDs As DatabaseServices.ObjectIdCollection
            Dim myObjID As DatabaseServices.ObjectId
            myDWG = ApplicationServices.Application.DocumentManager.MdiActiveDocument
            myDB = myDWG.Database
            myEd = myDWG.Editor
            myPSR = myEd.GetSelection()
            If Not IsNothing(myPSR.Value) Then
                MySS = myPSR.Value
                myTransMan = myDWG.TransactionManager
                myTrans = myTransMan.StartTransaction
                myObjIDs = New DatabaseServices.ObjectIdCollection(MySS.GetObjectIds)
                For Each myObjID In myObjIDs
                    myAcadEnt = myObjID.GetObject(DatabaseServices.OpenMode.ForRead)
                    If myAcadEnt.ObjectId.ObjectClass.IsDerivedFrom(RXClass.GetClass(GetType(DBText))) Then
                        PlantCode = myAcadEnt
                        If PlantCode.TextString.Equals("08") Then
                            myAcadEnt.UpgradeOpen()
                            myAcadEnt.ColorIndex = 4
                        End If
                        If PlantCode.TextString.Equals("20") Then
                            myAcadEnt.UpgradeOpen()
                            myAcadEnt.ColorIndex = 6
                        End If
                    End If
                    myTrans.Commit()
                    'myTrans.Dispose()
                    myEd.Regen()
                Next
                myTrans.Dispose()
                myTransMan.Dispose()
            End If
        End Sub

 The code only works on simple text, and not on the text within the blocks.  And if more that one item is selected, it throws an exception at

myAcadEnt = myObjID.GetObject(DatabaseServices.OpenMode.ForRead)

 Attached is a DWG with a couple of the blocks and some plain text I've been using for testing.  Any help in getting this to work would be greatly appreciated.

2 REPLIES 2
Message 2 of 3
hgasty1001
in reply to: bobmc

Hi,

 

This should help you: Changing Colour of Nested Entities

 

Gaston Nunez

Message 3 of 3
bobmc
in reply to: bobmc

I was just reading about GetNestedEntity when your reply came.  Seems like all the examples I had seen deal with changing block attributes or block table records, which aren't the same thing.  This should be a big help. I'll try to implement it in my project, and let you know.  Thanks!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost