Sketchblockcolor

Sketchblockcolor

Anonymous
Not applicable
684 Views
11 Replies
Message 1 of 12

Sketchblockcolor

Anonymous
Not applicable

I am trying to set the sketchblock layer color to red  in a part. What am i doing wrong??

Here is the code:

 

oline=ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketchBlockFilter,"Select a SketchBlock")
oBlock01=oline.ContainingSketchBlock
Dim oColor As Color
oColor = ThisApplication.TransientObjects.CreateColor(255, 0, 0)
oBlock01.Color.Setcolor=oColor

change 

0 Likes
Accepted solutions (1)
685 Views
11 Replies
Replies (11)
Message 2 of 12

bradeneuropeArthur
Mentor
Mentor

 Think you should do that curve by curve!

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 12

Anonymous
Not applicable

Ok, so how do you change the color of a simple line in a sketch? Keep in mind i am not talking about drawing documents but sketches in parts.......

0 Likes
Message 4 of 12

frederic.vandenplas
Collaborator
Collaborator

Hi @Anonymous 

Please try this code (assuming it's ilogic)

Select a sketchblock in an active sketch and run the code below

If ThisApplication.ActiveDocument.SelectSet.Count = 1 Then
If ThisApplication.ActiveDocument.SelectSet.Item(1).Type = kSketchBlockObject Then

Dim oSketchBlock As SketchBlock
oSketchBlock = ThisApplication.ActiveDocument.SelectSet.Item(1)

oSketchBlock.Color = ThisApplication.TransientObjects.CreateColor(255, 0, 0)

End If
Else

MessageBox.Show( "Please select a sketchblock")
End If

 

If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
0 Likes
Message 5 of 12

Anonymous
Not applicable

I tried the code  but i get this error

0 Likes
Message 6 of 12

frederic.vandenplas
Collaborator
Collaborator
Here it works inventor 2019 make sure in the options that you don't use straight vb code.
In inventor 2015 this does not seems to work, so maybe api in your current version is not supported?
If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
0 Likes
Message 7 of 12

Sergio.D.Suárez
Mentor
Mentor

1.jpg

There is a problem with the selection, this code is working but you must select the block from the browser, in the model tab inside the blocks folder that appears on the left

Dim oBlock As Inventor.SketchBlockDefinition 
oBlock = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketchBlockDefinitionFilter, "Select a SketchBlock in Browser")

Dim oColor As Color
oColor = ThisApplication.TransientObjects.CreateColor(255, 0, 0) 'Red

oBlock.Color = oColor
InventorVb.DocumentUpdate()

 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 8 of 12

frederic.vandenplas
Collaborator
Collaborator

Hi @Sergio.D.Suárez 

Now i see that you use the sketchblockdefinition instead of the blockdefinition

SelectionFilterEnum.kSketchBlockFilter

Try this but you still must select it in the treeview

Dim oBlock As Inventor.SketchBlock
oBlock = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketchBlockFilter, "Select a SketchBlock in Browser")

Dim oColor As Color
oColor = ThisApplication.TransientObjects.CreateColor(255, 0, 0) 'Red

oBlock.Color = oColor
InventorVb.DocumentUpdate()
If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
0 Likes
Message 9 of 12

frederic.vandenplas
Collaborator
Collaborator

@Sergio.D.Suárez 

With this code you can select in the sketch itself.

Dim oBlock As Inventor.SketchLine
oBlock = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketchBlockFilter, "Select a SketchBlock in Browser")

Dim oColor As Color
oColor = ThisApplication.TransientObjects.CreateColor(255, 0, 0) 'Red

oBlock.Parent.Color = oColor
InventorVb.DocumentUpdate()
If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
0 Likes
Message 10 of 12

bradeneuropeArthur
Mentor
Mentor

this will change the blockcolor in the definition:

 

Public Sub ChangeBlockColor()
Dim a As Application
Set a = ThisApplication

Dim prt As PartDocument
Set prt = a.ActiveDocument

Dim comps As SketchBlockDefinitions
Set comps = prt.ComponentDefinition.SketchBlockDefinitions

Dim skbd As SketchBlockDefinition
Set skbd = comps.Item(1)
Dim x As Byte Dim y As Byte Dim z As Byte x = 100 y = 100 z = 100 Dim oColor As Color Set oColor = ThisApplication.TransientObjects.CreateColor(x, y, z) skbd.Color = oColor prt.Update End Sub

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 11 of 12

Anonymous
Not applicable
Accepted solution

Thank you all for the help. This is the final working version of the code i have decided on. This way I can select the block in the sketch and not in the browsernode to change the color

 

Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument


Dim oBlocks As SketchBlockDefinitions
oBlocks  = oDoc.ComponentDefinition.SketchBlockDefinitions

oline = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketchBlockFilter, "Select a SketchBlock")
oBlock01=oline.ContainingSketchBlock

For i=1 To oBlocks.count
    If InStr(1,oBlock01.Name ,oBlocks.item(i).Name) > 0 Then
        Dim skbd As SketchBlockDefinition
        skbd = oBlocks.Item(i)
        Dim oColor As Color
        oColor = ThisApplication.TransientObjects.CreateColor(255, 0, 0) 'Red
        skbd.Color = oColor
        InventorVb.DocumentUpdate()
    End If
Next


 

0 Likes
Message 12 of 12

Sergio.D.Suárez
Mentor
Mentor

 

Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument
Dim oColor As Color
oColor = ThisApplication.TransientObjects.CreateColor(255, 0, 0) 'Red

oline = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketchBlockFilter, "Select a SketchBlock")
Dim oblockname As String
oblockname = Left(oline.ContainingSketchBlock.name, InStr(oline.ContainingSketchBlock.name, ":") - 1)

Dim oSketchBlock As Inventor.SketchBlockDefinition
For Each oSketchBlock In  oDoc.ComponentDefinition.SketchBlockDefinitions 
	If oSketchBlock.name = oblockname Then
	oSketchBlock.Color = oColor
	InventorVb.DocumentUpdate()
	End If
Next

 another form of code greetings


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes