Message 1 of 15
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I want to do the following:
Select a component in an assembly, open it, and execute an external rule that affect the opened part.
So far i have only accomplished to do this if instead of a external rule i add it to the part. This way the rule affects the part and not the assembly.
The problem is that whenever i try to use it with an external rule, it uses the data from the assembly.
I select a part (sheet metal) in an assembly and then i execute a macro that runs "Open_File"
Rule "Open_File":
'get currently selected component Dim oOccurrence As ComponentOccurrence Try oOccurrence = ThisDoc.Document.SelectSet.Item(1) Catch MessageBox.Show("Please select a component before running this rule.", "iLogic") Return End Try Dim doc As Document Dim CurFileName As String 'set the selected item oOccurrence = ThisApplication.ActiveDocument.SelectSet.Item(1) 'get the selected item document occurrence name doc = oOccurrence.Definition.Document 'Make file invisible oOccurrence.Visible = False Dim oName As String oName = oOccurrence.Name 'Open the file ThisApplication.Documents.Open(doc.FullFileName ,True) 'doc.FileName(False) = Filenamed 'Run rule 'iLogicVb.RunRule("componentName", "ruleName") 'iLogicVb.RunRule(oName, "Export_DWG") iLogicVb.RunExternalRule("C:\Users\fabio\Dropbox\INDUSSTOCK\Documentos CAD\_inventor definições_\Rules\Export_DWG")
Rule "Export_DWG":
'Check that this active document is a part file Imports System.Windows.Forms 'Wait for file to open System.Threading.Thread.CurrentThread.Sleep(1000) If ThisApplication.ActiveDocument.DocumentType <> kPartDocumentObject Then MessageBox.Show ("Please open a part document", "iLogic") End If 'Unselect faces ThisApplication.ActiveDocument.Save 'Set a reference to the active Dim oDoc As PartDocument oDoc = ThisApplication.ActiveDocument Dim oSelectSet As Selectset oSelectSet = oDoc.SelectSet oDoc.SelectSet.Clear() oQty = InputBox("Quantidade", "Quantidade", "1") 'If cancel then stop If oQty = "" Then Return End If 'Folder Name oFolder = ThisDoc.Path & "\Laser " & DateTime.Now.ToString("dd") & "_" & DateTime.Now.ToString("MM") & "\" 'File Name 'doc.ComponentDefinition.Parameters.UserParameters oFileName = ThisApplication.ActiveDocument.ComponentDefinition.Parameters.Parameter("Thickness")& "mm " & oQty & "x" & " "& ThisDoc.FileName(False) & ".dwg" 'without extension 'flat patternizor Dim oCompDef As SheetMetalComponentDefinition oCompDef = oDoc.ComponentDefinition 'Check for FlatPattern, if false create it, if true, unfold it If oCompDef.HasFlatPattern = False Then oCompDef.Unfold Else oCompDef.FlatPattern.Edit End If 'Check for the DXF folder and create it if it does not exist If Not System.IO.Directory.Exists(oFolder) Then System.IO.Directory.CreateDirectory(oFolder) End If 'SELECTION CODE, stop if operation is canceled (esc pressed) Dim oFace As Face oFace = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select a face") If (oFace Is Nothing) Then Return Else Call oDoc.SelectSet.Select(oFace) End If 'Add filename to memory for file save dialog (i don't fully understand this :p ) Dim Cm As CommandManager Cm = ThisApplication.CommandManager Cm.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, oFolder & oFilename ) 'EXPORT CODE 1 Dim oCtrlDef As ButtonDefinition oCtrlDef = ThisApplication.CommandManager.ControlDefinitions.Item("GeomToDXFCommand") Call oCtrlDef.Execute 'CLEAR selectset oDoc.SelectSet.Clear() 'save and close document ThisDoc.Save odoc.Close(True)
It seems that "Export_DWG" is affecting the assembly, as it is saying that the assembly file doesn't have the parameter "thickness"
Solved! Go to Solution.