Message 1 of 2
vba to copy ilogic document Forms
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to have a bit of code to update old drawings with rules and forms we have written into new templates. ideally these should be global forms but that hasn't happened at our office yet.
The rule part runs and works as expected. I cannot find any data on copying the forms. I can manually do this with mouse clicks so I expect it is written into the api but that is not accessible with vba. I made the assumption that it would be called forms but this does not seem to work.
Any help with accessing the form aspect of ilogic would be appreciated. My attempt is shown in the end of code below.
Thanks.
Sub ilogicCopyDeleteRules() Dim oApp As Application: Set oApp = Inventor.ThisApplication Dim oNewDoc As DrawingDocument Set oNewDoc = oApp.ActiveDocument Dim iLogicAuto As Object: Set iLogicAuto = GetiLogicAddin(ThisApplication) If (iLogicAuto Is Nothing) Then Exit Sub Dim oSourceFile As String 'oSourceFile = "testsourcefile.idw" If oSourceFile = "" Then Dim oOpenDialog As FileDialog Call ThisApplication.CreateFileDialog(oOpenDialog) With oOpenDialog .Filter = "Drawing(*.idw)|*.idw" .DialogTitle = "Pick ilogic Source Drawing" .OptionsEnabled = False .SuppressResolutionWarnings = True .ShowQuickLaunch = True '.ShowSave .ShowOpen If .fileName = "" Then Exit Sub Else oSourceFile = .fileName End If End With Set oOpenDialog = Nothing End If Dim oDoc As DrawingDocument 'Set oDoc = oApp.Documents.Open(oSourceFile, True) Set oDoc = oApp.Documents.Open(oSourceFile, False) 'don't show document Dim SourceParameters As UserParameters, SourceParameter As UserParameter Set SourceParameters = oDoc.Parameters.UserParameters Dim TargetParameters As UserParameters, TargetParameter As UserParameter Set TargetParameters = oNewDoc.Parameters.UserParameters Dim FoundParameter As Boolean: FoundParameter = False Dim oParameter As Parameter If MsgBox("Copy all parameters? you will need the names if fx params are blank" & vbCrLf & "Values will be from source document", vbYesNo) = vbYes Then For Each SourceParameter In SourceParameters For Each TargetParameter In TargetParameters If TargetParameter.Name = SourceParameter.Name Then FoundParameter = True Exit For End If Next If FoundParameter <> True Then Set oParameter = TargetParameters.AddByValue(SourceParameter.Name, SourceParameter.Value, SourceParameter.Units) If Not SourceParameter.ExpressionList Is Nothing Then If SourceParameter.ExpressionList.count > 0 Then Call oParameter.ExpressionList.SetExpressionList(SourceParameter.ExpressionList.GetExpressionList()) FoundParameter = False End If 'not sure if we should clear out parameters or just copy them.... for now I will just copy Next End If Dim RuleColl As ObjectCollection: Set RuleColl = ThisApplication.TransientObjects.CreateObjectCollection If MsgBox("Delete all iLogic rules in ALL components in this assembly?", vbYesNo) = vbNo Then Exit Sub 'delete all ilogic rules in target document Call iLogicAuto.DeleteAllRulesInDocument(oNewDoc) ' Build collection of rules Dim ruleName As String, rules As Object, rule As Object, ruleText As String Dim NewRule Set rules = iLogicAuto.rules(oDoc) If Not (rules Is Nothing) Then For Each rule In rules 'Call iLogicAuto.DeleteRule(oDoc, rule.Name) 'if you add the rule, then add the text to the rule, they do not run ruleName = rule.Name ruleText = rule.Text Set NewRule = iLogicAuto.AddRule(oNewDoc, rule.Name, "") 'rule.Text) NewRule.Text = rule.Text 'ilogic code 'Call RuleColl.Add(rule) Next End If 'Dim FormName As String, Forms As Object, Form As Object, FormText As String 'Dim NewForm 'Set Forms = iLogicAuto.ilogicFormsAndRulsEditor(oDoc) 'If Not (Forms Is Nothing) Then ' For Each Form In Forms ' 'Call iLogicAuto.DeleteRule(oDoc, rule.Name) ' ' 'if you add the rule, then add the text to the rule, they do not run ' FormName = Form.Name ' FormText = Form.Text ' Set NewForm = iLogicAuto.AddForm(oNewDoc, Form.Name, "") 'rule.Text) ' NewForm.Text = Form.Text 'ilogic code ' 'Call RuleColl.Add(rule) ' Next 'End If oDoc.Close End Sub