- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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:
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
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
@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")
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
@Anonymous
Did you see my last post? ![]()
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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? ![]()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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