I'd like to make a rule to open Part directly from the Assembly. It must be opened in a new window to make rules continuing to the next step (for ex. i'd like to make part from Standard part to Sheet metal)
I made
Dim oOcc As ComponentOccurrence oOcc = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "'Select an assembly occurrence.") If oOcc Is Nothing Then MsgBox("You did not select anything. Exiting.", , "") Exit Sub Else MsgBox("You selected an assembly occurrrence named " & oOcc.Name & ".ipt") End If Try ThisDoc.Launch(Component.InventorComponent(oOcc).Definition.Document.FullFileName) Catch MsgBox("File has not been saved or other issue opening file occurred") Exit Sub End Try
I made start, but then I get error in line
ThisDoc.Launch(Component.InventorComponent(oOcc).Definition.Document.FullFileName)
Solved! Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
Hi @damjan_baraga ,
This should work for you:
Dim oOcc As ComponentOccurrence oOcc = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "'Select an assembly occurrence.") If oOcc Is Nothing Then MsgBox("You did not select anything. Exiting.", , "") Exit Sub Else Dim oDoc As Document = oOcc.Definition.Document ThisApplication.Documents.Open(oDoc.FullFileName) End If
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
After I put whole rule I get error in same line.
The whole rule is:
Dim oOcc As ComponentOccurrence oOcc = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "'Select an assembly occurrence.") If oOcc Is Nothing Then MsgBox("You did not select anything. Exiting.", , "") Exit Sub Else Dim oDoc As Document = oOcc.Definition.Document ThisApplication.Documents.Open(oDoc.FullFileName) End If Dim PartDoc As PartDocument PartDoc = ThisApplication.ActiveDocument ' Convert it to a sheet metal type. PartDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Dim smDef As SheetMetalComponentDefinition smDef = PartDoc.ComponentDefinition ' Unfold the part. This will activate the flat pattern environment. smDef.Unfold ' Exit the flat pattern environment. smDef.FlatPattern.ExitEdit 'On Error Resume Next 'Dim oDoc As PartDocument oDoc = ThisApplication.ActiveDocument 'Dim CadlineSheetMetal As SheetMetalComponentDefinition CadlineSheetMetal = oDoc.ComponentDefinition 'CadlineSheetMetal.FlatPattern.Delete CadlineSheetMetal.Unfold Cadline = ThisApplication.ActiveDocument.ComponentDefinition X= 10*( Cadline.RangeBox.MaxPoint.X - Cadline.RangeBox.MinPoint.X) Y= 10*( Cadline.RangeBox.MaxPoint.Y - Cadline.RangeBox.MinPoint.Y) Z= 10*( Cadline.RangeBox.MaxPoint.Z - Cadline.RangeBox.MinPoint.Z) Parameter.Quiet = True THICKNESS = MinOfMany(X, Y, Z) ThisDoc.Document.ComponentDefinition.UseSheetMetalStyleThickness = False Dim oPartDoc As PartDocument oPartDoc = ThisApplication.ActiveDocument Dim oSheetMetalCompDef As SheetMetalComponentDefinition oSheetMetalCompDef = oPartDoc.ComponentDefinition Dim oThicknessParam As Parameter oThicknessParam = oSheetMetalCompDef.Thickness oThicknessParam.Value = THICKNESS/10 'oPartDoc.Update LENGTH = MaxOfMany(X, Y, Z) If X < LENGTH Then WIDTH = X End If If Y < LENGTH Then WIDTH = Y End If If Z < LENGTH Then WIDTH = Y End If iProperties.Value("Custom", "LENGTH") = Round(LENGTH, 1) iProperties.Value("Custom", "WIDTH") = Round(WIDTH, 1) iProperties.Value("Custom", "THICKNESS") = Round(THICKNESS, 1) iProperties.Value("Project", "Authority") = iProperties.Value("Custom", "THICKNESS") iProperties.Value("Summary", "Comments") = "laser" RuleParametersOutput() iLogicVb.UpdateWhenDone = True oDoc = ThisApplication.ActiveDocument CadlineSheetMetal = oDoc.ComponentDefinition InventorVb.DocumentUpdate() 'set iproperty to use ISO view on save oDoc.SetThumbnailSaveOption _ (ThumbnailSaveOptionEnum.kActiveComponentIsoViewOnSave) oDoc = ThisApplication.ActiveEditDocument 'get current colorcheme name oColorScheme = ThisApplication.ActiveColorScheme.Name 'Change to Presentation ThisApplication.ColorSchemes.Item("Presentation").Activate ThisApplication.ColorSchemes.BackgroundType = 52737 'set iproperty to use ISO view on save oDoc.SetThumbnailSaveOption _ (ThumbnailSaveOptionEnum.kActiveComponentIsoViewOnSave) ThisDoc.Save 'Change back to original scheme ThisApplication.ColorSchemes.Item(oColorScheme).Activate Call PartDoc.Close(True)
The rule works without your add. This I get:
Here is an updated version of your code.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Dim oOcc As ComponentOccurrence oOcc = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "'Select an assembly occurrence.") If oOcc Is Nothing Then MsgBox("You did not select anything. Exiting.", , "") Exit Sub End If Dim oDoc As Document oDoc = ThisApplication.Documents.Open(oOcc.Definition.Document.FullFileName) ' Convert it to a sheet metal type. oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Dim smDef As SheetMetalComponentDefinition smDef = oDoc.ComponentDefinition ' Unfold the part. This will activate the flat pattern environment. smDef.Unfold ' Exit the flat pattern environment. smDef.FlatPattern.ExitEdit oDoc = ThisApplication.ActiveDocument 'Dim CadlineSheetMetal As SheetMetalComponentDefinition CadlineSheetMetal = oDoc.ComponentDefinition 'CadlineSheetMetal.FlatPattern.Delete CadlineSheetMetal.Unfold Cadline = ThisApplication.ActiveDocument.ComponentDefinition X = 10 * (Cadline.RangeBox.MaxPoint.X - Cadline.RangeBox.MinPoint.X) Y = 10 * (Cadline.RangeBox.MaxPoint.Y - Cadline.RangeBox.MinPoint.Y) Z = 10 * (Cadline.RangeBox.MaxPoint.Z - Cadline.RangeBox.MinPoint.Z) Parameter.Quiet = True THICKNESS = MinOfMany(X, Y, Z) Try ThisDoc.Document.ComponentDefinition.UseSheetMetalStyleThickness = False Catch MsgBox("could not set 'UseSheetMetalStyleThickness'", , "iLogic") Exit Sub End Try Dim oSheetMetalCompDef As SheetMetalComponentDefinition oSheetMetalCompDef = oDoc.ComponentDefinition Dim oThicknessParam As Parameter oThicknessParam = oSheetMetalCompDef.Thickness oThicknessParam.Value = THICKNESS / 10 'oDoc.Update LENGTH = MaxOfMany(X, Y, Z) If X < LENGTH Then WIDTH = X End If If Y < LENGTH Then WIDTH = Y End If If Z < LENGTH Then WIDTH = Y End If iProperties.Value("Custom", "LENGTH") = Round(LENGTH, 1) iProperties.Value("Custom", "WIDTH") = Round(WIDTH, 1) iProperties.Value("Custom", "THICKNESS") = Round(THICKNESS, 1) iProperties.Value("Project", "Authority") = iProperties.Value("Custom", "THICKNESS") iProperties.Value("Summary", "Comments") = "laser" RuleParametersOutput() iLogicVb.UpdateWhenDone = True CadlineSheetMetal = oDoc.ComponentDefinition InventorVb.DocumentUpdate() 'set iproperty to use ISO view on save oDoc.SetThumbnailSaveOption _ (ThumbnailSaveOptionEnum.kActiveComponentIsoViewOnSave) 'get current colorcheme name oColorScheme = ThisApplication.ActiveColorScheme.Name 'Change to Presentation ThisApplication.ColorSchemes.Item("Presentation").Activate ThisApplication.ColorSchemes.BackgroundType = 52737 'set iproperty to use ISO view on save oDoc.SetThumbnailSaveOption _ (ThumbnailSaveOptionEnum.kActiveComponentIsoViewOnSave) oDoc.Save 'Change back to original scheme ThisApplication.ColorSchemes.Item(oColorScheme).Activate Call oDoc.Close(True)
Its working till here:
Try ThisDoc.Document.ComponentDefinition.UseSheetMetalStyleThickness = False Catch MsgBox("Could not set 'UseSheetMetalStyleThickness'", , "iLogic") Exit Sub End Try
Then I get:
My apologies, I put that error catch in, but I misinterpreted the error. It should be as shown below:
Try oDoc.ComponentDefinition.UseSheetMetalStyleThickness = False Catch MsgBox("could not set 'UseSheetMetalStyleThickness'", , "iLogic") Exit Sub End Try
iProperties.Value(oOcc.Name, "Custom", "LENGTH") = Round(LENGTH, 2) iProperties.Value(oOcc.Name, "Custom", "WIDTH") = Round(WIDTH, 2) iProperties.Value(oOcc.Name, "Custom", "THICKNESS") = Round(THICKNESS, 2) iProperties.Value(oOcc.Name, "Project", "Authority") = iProperties.Value("Custom", "THICKNESS") iProperties.Value(oOcc.Name, "Summary", "Comments") = "laser"
Can't find what you're looking for? Ask the community or share your knowledge.