change color and thickness of sketch line

change color and thickness of sketch line

Anonymous
Not applicable
1,467 Views
10 Replies
Message 1 of 11

change color and thickness of sketch line

Anonymous
Not applicable

Hi,

 

I want change properties (color and thickness) of sketch line in assembly/part, when I have open assembly,but not active sketch.

Rule:

 

Dim oSketch as Sketch

oSketch=thisApplication.ActiveEditObject   ´here is a problem, because rule run only when is sketch active!!!

 

Dim oColor as color

oColor = thisApplication. TransientObject.CreateColor(0,0,0)

 

osketch.SketchLines(2).OverrideColor=oColor

---------------------

Question are:

1) How will run rule, when is sketch not active, but I have assembly/part open?

2) How change thickness of sketch line??

3) Where/how find out how is named this line/curve in sketch?? ( SketchLines(2) or SketchLines(99) )

4) command for white color??

 

Thanks for your time and reply!

0 Likes
Accepted solutions (1)
1,468 Views
10 Replies
Replies (10)
Message 2 of 11

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @Anonymous 

To get your rule to run, I'd recommend getting the sketch by its name:

Dim oDoc As Document = ThisDoc.Document
Dim oSketch As PlanarSketch = oDoc.ComponentDefinition.Sketches.Item("sketch name") 'sketch name = Name of sketch
Dim oColor As Color
oColor = ThisApplication.TransientObjects.CreateColor(255, 255, 255) 'White

Dim oLine As SketchLine = oSketch.SketchLines(2)
oLine.OverrideColor = oColor
oLine.LineWeight = 2 'Set Lineweight

Identifying a specific line is a bit difficult. You could use RefKeys like @Anonymous is doing here:

https://forums.autodesk.com/t5/inventor-customization/change-sketch-constraints-programmatically-ilogic/td-p/9542773

 

If you have the sketch visible though, maybe it's enough to just have the user pick the line like this?

'Get the sketchLine
Dim oLine As SketchLine = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketchCurveLinearFilter, "Pick the sketchline")
'Set the color
oLine.OverrideColor = ThisApplication.TransientObjects.CreateColor(255, 255, 255)
'Set the line weight
oLine.LineWeight = 2

 

Message 3 of 11

Anonymous
Not applicable

Hi  JhoelForshav,

 

I have tried your first code. and I have error in the rule. - Memember not found......

I think, that problem is in this row:

Dim oSketch As PlanarSketch = oDoc.ComponentDefinition.Sketches.Item("sketch name") 

 Do you know why?

0 Likes
Message 4 of 11

JhoelForshav
Mentor
Mentor

@Anonymous 

You must replace "sketch name" with the name of the sketch that the line is in 🙂

 

Ex:

Dim oSketch As PlanarSketch = oDoc.ComponentDefinition.Sketches.Item("Sketch1")  
0 Likes
Message 5 of 11

JhoelForshav
Mentor
Mentor

Or did I misunderstand maybe. Do you want to run the rule from an assemmbly and find a sketch by a specific name in any of the occurrences in the assembly?

Then something like this maybe?

This rule changes the color and thickness of sketchline(2) in all sketches with the selected name within any component in the assembly.

 

Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oSketchName As String = "Sketch1" 'Name of the sketch
For Each oRefDoc As Document In oAsm.AllReferencedDocuments
	If oRefDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Or oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject
	If oAsm.ComponentDefinition.Occurrences.AllReferencedOccurrences(oRefDoc).Count > 0
		Try
			Dim oSketch As PlanarSketch = oRefDoc.ComponentDefinition.Sketches.Item(oSketchName) 'sketch name = Name of sketch
			Dim oColor As Color
			oColor = ThisApplication.TransientObjects.CreateColor(255, 255, 255) 'White

			Dim oLine As SketchLine = oSketch.SketchLines(2)
			oLine.OverrideColor = oColor
			oLine.LineWeight = 2 'Set Lineweight
		Catch
			'Sketch is not in document or Sketchline with selected index not in sketch
		End Try
	End If
End If
Next

iLogicVb.UpdateWhenDone = True
Message 6 of 11

Anonymous
Not applicable

Yes I know. This I did and I have this error

0 Likes
Message 7 of 11

JhoelForshav
Mentor
Mentor

@Anonymous 

Did you see my last post? 🙂

0 Likes
Message 8 of 11

Anonymous
Not applicable

now yes. I´m trying it

0 Likes
Message 9 of 11

Anonymous
Not applicable

Ok. I have tangled head. 

First I want say that second rule is ok - run. no problem

 

First rule: I made part- .ipt. I created rectanguler sketch and model. This rule I have tried on rectangle sketch.

when I have open only this part. This rule write error with membernotfound...

 

Then I have tried the last (third rule) - I made assambly- .iam . I put the part with rectangle sketch. I have tried third rule on sketch of part. No problem. This rule run.

then I have tried made only rectanguler sketch in assambly with part. And first rule I put in the assambly and run!.

 

Then I found out that when I have open assembly and I open part. - First rule run in part (but condition is that you must have open assembly)
Then I tried closed all files and open only part and first rule wrote error with memeber

 

So it means I don´t know why, that first rule run in part, when I have open assembly with part.

 

Do you know why??

Do you understand me what I mean? 😄

 

 

0 Likes
Message 10 of 11

JhoelForshav
Mentor
Mentor

I think I understand what you want now.

Try this:

 

Sub Main
	Dim oSketchName As String = "Sketch1" 'Name of the sketch
	updateLine(ThisDoc.Document, oSketchName)
	If ThisDoc.Document.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject
		Dim oAsm As AssemblyDocument = ThisDoc.Document
		For Each oRefDoc As Document In oAsm.AllReferencedDocuments
			If oRefDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Or oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject
				If oAsm.ComponentDefinition.Occurrences.AllReferencedOccurrences(oRefDoc).Count > 0
					updateLine(oRefDoc, oSketchName)
				End If
			End If
		Next
	End If

	iLogicVb.UpdateWhenDone = True
End Sub
Sub updateLine(oDoc As Document, oName As String)
	Try
		Dim oSketch As PlanarSketch = oDoc.ComponentDefinition.Sketches.Item(oName) 'sketch name = Name of sketch
		Dim oColor As Color
		oColor = ThisApplication.TransientObjects.CreateColor(255, 255, 255) 'White

		Dim oLine As SketchLine = oSketch.SketchLines(2)
		oLine.OverrideColor = oColor
		oLine.LineWeight = 2 'Set Lineweight
	Catch
		'Sketch is not in document or Sketchline with selected index not in sketch
	End Try
End Sub
Message 11 of 11

Anonymous
Not applicable

Ok. Thanks for your help.

Only for information in assembly works all your command. In part I have problem with first rule.... 

The last question (this week 🙂 ).

 1. command for change style of line in chart ?

 

 

nice a weekend

  

0 Likes