Change Text Color at Drawing Sketch Symbol

Change Text Color at Drawing Sketch Symbol

dgreatice
Collaborator Collaborator
2,122 Views
5 Replies
Message 1 of 6

Change Text Color at Drawing Sketch Symbol

dgreatice
Collaborator
Collaborator

Anyone can help me to get the right code below, i cant change text color at drawing Sketch Symbol like the picture.

 

Public Sub EditSymbols()
Dim odoc As DrawingDocument
Set odoc = ThisApplication.ActiveDocument
Dim osymb As SketchedSymbolDefinition
Dim oColor As Color
Set oColor = ThisApplication.TransientObjects.CreateColor(0, 0, 0)
oColor.ColorSourceType = ColorSourceTypeEnum.kLayerColorSource
Dim oText As TextBox

Dim x As Long
x = 0
Dim y As Long
y = 0
For Each osymb In odoc.SketchedSymbolDefinitions
x = x + 1
Set osymb = odoc.SketchedSymbolDefinitions.Item(x)
Dim oSketch As DrawingSketch
Call osymb.Edit(oSketch)
For Each oText In osymb.Sketch.TextBoxes
y = y + 1
Set oText = osymb.Sketch.TextBoxes.Item(y)
oText.Color.ColorSourceType = ColorSourceTypeEnum.kLayerColorSource
Next
y = 0
osymb.ExitEdit (True)
Next
End Sub

 

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes
Accepted solutions (1)
2,123 Views
5 Replies
Replies (5)
Message 2 of 6

dgreatice
Collaborator
Collaborator
Anyone can help me?
Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes
Message 3 of 6

dgreatice
Collaborator
Collaborator

Request anwer, please. Thanks

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes
Message 4 of 6

Anonymous
Not applicable
Accepted solution

 

I had the same issue I was cleaning up blocks and there are a lot of them. I wanted to change the textboxes to bylayer.

 

The following is iLogic code, but you can the skeleton and apply it to your vb code

 

I had to use item(x) format in order for it to work.. not sure why...

 

On Error Resume Next
iLogicVb.UpdateWhenDone = True
Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSketch As DrawingSketch
Dim oColor As color
Dim oSymDefName As String
Dim x As Integer = 1
Dim y As Integer = 1
Dim oSymDef As SketchedSymbolDefinition
For Each SketchedSymbolDefinition In odoc.SketchedSymbolDefinitions
        oSymDefName = odoc.SketchedSymbolDefinitions.Item(x).Name 'gets the name of the block
        oSymDef = odoc.SketchedSymbolDefinitions.Item(oSymDefName) 'uses the name of the block
        oSymDef.Edit(oSketch)
        For Each TextBox In oSketch.TextBoxes
        oColor = oSketch.TextBoxes.Item(y).Color 'gets the current color
        oColor.ColorSourceType = ColorSourceTypeEnum.kLayerColorSource 'Makes the current color bylayer
        oSketch.TextBoxes.Item(y).Color = oColor  'assigns the color with bylayer
y=y+1 Next y=1 x=x+1 oSymDef.ExitEdit (True) Next

 

Message 5 of 6

dgreatice
Collaborator
Collaborator

Hi,

 

Thank for you code, its work.

I make simple code now.

 

    Dim oDoc As DrawingDocument
    oDoc = ThisApplication.ActiveDocument
    Dim osymb As SketchedSymbolDefinition
    Dim oText As TextBox
    Dim oSketch As DrawingSketch
    Dim oColor As Color
   
    For Each osymb In oDoc.SketchedSymbolDefinitions
        Call osymb.Edit(oSketch)
        For Each oText In osymb.Sketch.TextBoxes
            oColor = oText.Color
            oColor.ColorSourceType = ColorSourceTypeEnum.kLayerColorSource
            Dim Y As Long
            For Y = 1 To oSketch.TextBoxes.Count
                oSketch.TextBoxes.Item(Y).Color = oColor
            Next
        Next
        osymb.ExitEdit (True)
    Next

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
Message 6 of 6

JREVKAP8
Explorer
Explorer

I want do the the same, but for Sketch lines as well. I can't get it to work though. I tried simply replacing "textbox" with "sketchLine" in the code, but no luck. 


Could you help me with this?

0 Likes