Update a few things with AllReferencedDocuments

Update a few things with AllReferencedDocuments

machiel.veldkamp
Collaborator Collaborator
1,965 Views
12 Replies
Message 1 of 13

Update a few things with AllReferencedDocuments

machiel.veldkamp
Collaborator
Collaborator

I want to update all ipt's in a assemblies. We have older files which we need to convert for vault. 

 

They are 2012 ipt's and they have materials that arent good, older draftsman that don't work here anymore. Some iProperties need to be deleted. 

 

In other words.... iLogic!

 

 

So. I have made rules for all individual things but now I want to combine it in one rule that I can unleash upon large assemblies. 

 

How? 

 

I thought of make a Sub Main() which iterates the .iam and for every ipt it calls a sub and does it's thing before moving to the next one. 

 

I think I'm making a rookie mistake somwhere and I'm stuck. 

 

I'll dump my code here first.

 

SyntaxEditor Code Snippet

Sub Main()

'Define the open document
Dim openDoc As Document
openDoc = ThisDoc.Document
Dim docFile As Document
'kAssemblyDocumentObject = 12291
If openDoc.DocumentType = 12291 Then
    'Iterate though the part files in the assembly
    For Each docFile In openDoc.AllReferencedDocuments
        'kPartDocumentObject = 12290
        If docFile.DocumentType = 12290 Then
        
            UpdateStylesStandards(docFile)
            DeleteParameters(docFile)
            UpdateiProperties(docFile)
            'UpdateMaterials(docFile) UNFINNISHED
            
        Else 
            MessageBox.Show("Something went wrong, probably a iam", "Error in Sub MAIN")
        End If
    Next
    Else
    
End If
iLogicVb.UpdateWhenDone = True        
        
End Sub
        
Sub UpdateMaterials(docfile As Document)
MessageBox.Show(docfile.FullFileName, "UpdateMaterials Name") 'test to see if I can call a ipt in an each loop.
    
    docfile = ThisApplication.ActiveDocument 
    
    Dim i As Integer
    
    Dim oMaterial As String
    oMaterial = iProperties.Material
    
    If oMaterial = "1.4301" Then 
        Try 
            iProperties.Material = "1.4301-304"
            Catch 
            i = i+1
        End Try
        
        Else 
    End If
    
    If oMaterial = "1.4401" Then 
        Try 
            iProperties.Material = "1.4401-316"
            Catch 
            i = i+1
        End Try
        
        Else 
    End If
    
    If i > 1 Then
        MessageBox.Show("Mislukt. Ben je wel uitgecheckt?", "watwatwaaat?")
    End If
    
    iProperties.Material = "1.4301-304"
    '

End Sub

Sub UpdateiProperties(docfile As Document)
'MessageBox.Show(docfile.FullFileName, "UpdateiProperties Name")

End Sub

Sub UpdateStylesStandards(docfile As Document)
'MessageBox.Show(docfile.FullFileName, "UpdateStylesStandards Name")
End Sub

Sub DeleteParameters(docfile As Document)
'MessageBox.Show(docfile.FullFileName, "DeleteParameters")

docfile = ThisApplication.ActiveDocument 
MessageBox.Show(docfile.FullFileName, "UpdateMaterials Name")
Dim param1 As Parameter
Dim param2 As Parameter
Dim param3 As Parameter
Dim param4 As Parameter

    Try
        param1=docfile.ComponentDefinition.Parameters.Item("BREEDTE") 
        param1.Delete 
        param2=docfile.ComponentDefinition.Parameters.Item("LENGTE")
        param2.Delete 
        param3=docfile.ComponentDefinition.Parameters.Item("DIKTE") 
        param3.Delete 
        param4=docfile.ComponentDefinition.Parameters.Item("DIAM")
        param4.Delete 
        
    Catch
    End Try
    
    Try
        param1=docfile.ComponentDefinition.Parameters.Item("BREEDTE_1") 
        param1.Delete
        param2=docfile.ComponentDefinition.Parameters.Item("DIAM_1")
        param2.Delete 
        param3=docfile.ComponentDefinition.Parameters.Item("LENGTE_1")
        param3.Delete 
        param4=docfile.ComponentDefinition.Parameters.Item("DIKTE_1") 
        param4.Delete 
    Catch
    
    End Try


End Sub


 

So yes. I'm focussing on the Parameter one right now. Why doesn't it work?

I'm calling the ipt. I checked that it's active (I think) and I should be deleting the Parameters?

 

 

Anyone that can kick me in the right direction? 

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
0 Likes
1,966 Views
12 Replies
Replies (12)
Message 2 of 13

Owner2229
Advisor
Advisor

Hey, try this:

 

Sub Main()
    Dim oDoc As Document = ThisApplication.ActiveDocument
    If oDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Exit Sub
    OneDown(oDoc) 'Handle SubAssemblies
    iLogicVb.UpdateWhenDone = True        
End Sub

Private Sub OneDown(oDoc As Document)
    For Each docFile As Document In oDoc.AllReferencedDocuments
        If oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then OneDown(docFile)
        If docFile.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then Continue For
        UpdateStylesStandards(docFile)
        DeleteParameters(docFile)
        UpdateiProperties(docFile)
        'UpdateMaterials(docFile) UNFINNISHED
    Next
End Sub

Private Sub UpdateMaterials(oDoc As Document)
    MessageBox.Show(oDoc.FullFileName, "UpdateMaterials Name")
    Dim oMaterial As String = iProperty(oDoc, Material).Expression
    If oMaterial = "1.4301" Then 
        iProperty(oDoc, Material).Expression = "1.4301-304"
    ElseIf oMaterial = "1.4401" Then 
        iProperty(oDoc, Material).Expression = "1.4401-316"
    End If
    'iProperty(oDoc, Material).Expression = "1.4301-304"  ???
End Sub

Private Sub UpdateiProperties(oDoc As Document)
    'iProperty(oDoc, "iProName").Expression = "value" 'For Project iProperties
    'iPropertyUser(oDoc, "iProName").Expression = "value" 'For Custom iProperties
End Sub

Private Sub UpdateStylesStandards(oDoc As Document)
    
End Sub

Private Sub DeleteParameters(oDoc As Document)
    MessageBox.Show(oDoc.FullFileName, "DeleteParameters")
    Dim oParas As Parameters = oDoc.ComponentDefinition.Parameters
    Dim ParaToDel() As String = {"BREEDTE", "LENGTE", "DIKTE", "DIAM", "BREEDTE_1", "DIAM_1", "LENGTE_1", "DIKTE_1"}
    For Each oPara As String In ParaToDel
        Try
            Dim param1 As Parameter = oParas.Item(oPara)
param1.Delete Catch End Try Next End Sub Public Function iProperty(oDoc As Inventor.Document, oProp As String) As Inventor.Property Dim oPropsets As PropertySets = oDoc.PropertySets Dim oPropSet As PropertySet = oPropsets.Item("{32853F0F-3444-11D1-9E93-0060B03C1CA6}") Try iProperty = oPropSet.Item(oProp) Catch oPropSet.Add("", oProp) iProperty = oPropSet.Item(oProp) End Try oPropsets = Nothing oPropSet = Nothing End Function Public Function iPropertyUser(oDoc As Inventor.Document, oProp As String) As Inventor.Property Dim oPropsets As PropertySets = oDoc.PropertySets Dim oPropSet As PropertySet = oPropsets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}") Try iPropertyUser = oPropSet.Item(oProp) Catch oPropSet.Add("", oProp) iPropertyUser = oPropSet.Item(oProp) End Try oPropsets = Nothing oPropSet = Nothing End Function 

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 3 of 13

machiel.veldkamp
Collaborator
Collaborator

@Owner2229 Thanks again! You're the best!


So. Very interesting way to add the properties. 

The error I get is that the material isn't an expression. It's a 'type'

 

SyntaxEditor Code Snippet

 Dim oMaterial As String = iProperty(oDoc, Material).Expression

 

 

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
0 Likes
Message 4 of 13

Owner2229
Advisor
Advisor

Sorry, I've forgot to put it in brackets. Also, you're welcomed.

 

Private Sub UpdateMaterials(oDoc As Document)
    MessageBox.Show(oDoc.FullFileName, "UpdateMaterials Name")
    Dim oMaterial As String = iProperty(oDoc, "Material").Expression
    If oMaterial = "1.4301" Then 
        iProperty(oDoc, "Material").Expression = "1.4301-304"
    ElseIf oMaterial = "1.4401" Then 
        iProperty(oDoc, "Material").Expression = "1.4401-316"
    End If
    'iProperty(oDoc, "Material").Expression = "1.4301-304"  ???
End Sub

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 5 of 13

machiel.veldkamp
Collaborator
Collaborator

Hey @Owner2229

 

Can you help me out once more? I'm struggeling to figure something out. 

 

Public Function iProperty

How does this function function?

 

 

Private Sub UpdateiProperties(oDoc As Document)
    'iProperty(oDoc, "iProName").Expression = "value" 'For Project iProperties
    'iPropertyUser(oDoc, "iProName").Expression = "value" 'For Custom iProperties
End Sub

 

 

Public Function iProperty(oDoc As Inventor.Document, oProp As String) As Inventor.Property
	Dim oPropsets As PropertySets = oDoc.PropertySets
	Dim oPropSet As PropertySet = oPropsets.Item("{32853F0F-3444-11D1-9E93-0060B03C1CA6}")
	Try
		iProperty = oPropSet.Item(oProp)
	Catch
		oPropSet.Add("", oProp)
		iProperty = oPropSet.Item(oProp)
	End Try
	oPropsets = Nothing
	oPropSet = Nothing
End Function

 

 

 I want to insert a few things in the Custom props. 
Strings with text

Timestamp

Boolean (Ordered value)

 

I tried this:

 

SyntaxEditor Code Snippet

Private Sub UpdateiProperties(oDoc As Document)
    'iProperty(oDoc, "Title").Expression = "0" 'For Project iProperties
    'iPropertyUser(oDoc, "iProName").Expression = "value" 'For Custom iProperties
    
    CustomPropertySet = oDoc.PropertySets.Item("Inventor User Defined Properties")
    For Each oCustProp In CustomPropertySet
        'delete the custom iProperty
        oCustProp.Delete
    Next
    MessageBox.Show("1", "Title")

    
    Dim strJOBORDER As String
    
    MessageBox.Show("3", "Title")
    iPropertyUser(oDoc, "JOB ORDER").Expression = strJOBORDER
    
     
    
End Sub

 

Now I understand that after the "=" the text is a string anyway. But what if I input a date there?

Sorry if my question is dumb.

 

 

I also want to ask you about the normal iProperty function.

 

I tried changing the Title and Description but all it does now is set that as values in the .iam I'm working in.

 

 

Thanks for all the energy you're putting into this.  

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
0 Likes
Message 6 of 13

Owner2229
Advisor
Advisor

Hey, if you want to work with custom (user defined) iproperties, use the second function "iPropertyUser"

 

E.g.:

 

 

'Delete custom iProperty "MyBox":
iPropertyUser(oDoc, "MyBox").Delete

'Create new custom text iProperty "MyText" and give it value "boo":
iPropertyUser(oDoc, "MyText).Expression = "boo"
'Create new custom boolean iProperty "MyBol" and give it value "true": iPropertyUser(oDoc, "MyBol").Value = True 'Create new custom timestamp iProperty "MyTime" and give it "Now" as a value: iPropertyUser(oDoc, "MyTime").Value = Now()

 

Easy, right? That's why is the function designed as it is, to handle the creation (etc.) itself.

Notice the difference, for text I'm using ".Expression" and for else I'm using ".Value".

 

As for the Title and Description update, if you put it in the "Private Sub UpdateiProperties" it will work with the sub-files.

 

Also, there's no need for this (red) line, as you're already referring to "AllReferencedDocuments". My mistake.

It even causes a small loop, as there is oDoc instead of docFile.

 

Private Sub OneDown(oDoc As Document)
    For Each docFile As Document In oDoc.AllReferencedDocuments
        If oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then OneDown(docFile) 

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 7 of 13

machiel.veldkamp
Collaborator
Collaborator

Aaaaaah. I see. Yeah I found the page in the API as well where it says what name table I should use. 

 

Thanks man. This helps a ton. 

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
0 Likes
Message 8 of 13

machiel.veldkamp
Collaborator
Collaborator

Dump the rule here:

 

Alright. This here works. For the future. If you're finding this through google: Some things here might not work for you but the concept is here. 

 

AddRule() is broken at the moment. I need to explore that option first.

 

SyntaxEditor Code Snippet

Sub Main()
    Dim oDoc As Document = ThisApplication.ActiveDocument
    If oDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Exit Sub
    i =  MessageBox.Show("WARNING: SLOW PROCESS. ARE YOU SURE YOU WANT TO DO THIS? DO NOT USE IN VAULT", "FIX EVERYTHING", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
    If i= vbYes Then
        OneDown(oDoc) 'Handle SubAssemblies
    End If
    
    iLogicVb.UpdateWhenDone = True        
End Sub

Private Sub OneDown(oDoc As Document)
    For Each docFile As Document In oDoc.AllReferencedDocuments
        'If oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then OneDown(docFile)
        If docFile.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then Continue For
        DeleteParameters(docFile) 'Finnished
        UpdateMaterials(docFile) 'Finnished
        UpdateiProperties(docFile) 'Finnished
        'AddRule(docFile) UNFINNISHED. HOW DOES THIS WORK???
    Next
End Sub

Private Sub UpdateMaterials(oDoc As Document)
    
    Dim oMaterial As String = iProperty3(oDoc, "Material").Expression
    'MessageBox.Show("Okay", "Title")

    If oMaterial = "1.4301" Then 
        iProperty3(oDoc, "Material").Expression = "1.4301-304"
    ElseIf oMaterial = "1.4401" Then 
        iProperty3(oDoc, "Material").Expression = "1.4401-316"
    End If
    'iProperty(oDoc, "Material").Expression = "1.4301-304"  'make 1.4301-304 every part that is unknown
    
End Sub

Private Sub UpdateiProperties(oDoc As Document)
    CustomPropertySet = oDoc.PropertySets.Item("Inventor User Defined Properties")
    For Each oCustProp In CustomPropertySet
        'delete the custom iProperty
        oCustProp.Delete
    Next
        
    iPropertyUser(oDoc, "FINNISH").Expression         = ""
    iPropertyUser(oDoc, "JOB ORDER").Expression     = ""
    iPropertyUser(oDoc, "Mass").Value                 = oDoc.ComponentDefinition.MassProperties.Mass
    iPropertyUser(oDoc, "ORDER").Value                 = True
    iPropertyUser(oDoc, "SALES ORDER").Value         = "strSALESORDER"
    iPropertyUser(oDoc, "Stock MATL DESC").Expression    = ""
    iPropertyUser(oDoc, "SIMILAR TO").Value         = "N/A"
    iPropertyUser(oDoc, "VLDS_AcceptCnt").Value     = 0
    iPropertyUser(oDoc, "VLDS_FailCnt").Value         = 0
    iPropertyUser(oDoc, "VLDS_Profile").Value         = "RELCO US JO PART"
    iPropertyUser(oDoc, "VLDS_Timestamp").Value     = Now()
    
    
    iProperty(oDoc, "Revision Number").Expression     = "0" 'For Project iProperties
    iProperty(oDoc, "Title").Expression             = "" 'For Project iProperties
    iProperty(oDoc, "Subject").Expression             = ""
    iProperty(oDoc, "Author").Expression             = ""
    iProperty(oDoc, "Comments").Expression             = ""
    
    iProperty2(oDoc, "Manager").Expression            = ""
    iProperty2(oDoc, "Company").Expression            = ""
    
    iProperty3(oDoc, "Project").Expression             = ""
    iProperty3(oDoc, "Description").Expression         = ""
    iProperty3(oDoc, "Vendor").Expression             = ""
    iProperty3(oDoc, "Designer").Value                 =  ThisApplication.UserName
    iProperty3(oDoc, "Creation Time").Value         = Now()
    

    
End Sub

Private Sub DeleteParameters(oDoc As Document)
    
    Dim oParas As Parameters = oDoc.ComponentDefinition.Parameters
    Dim ParaToDel() As String = {"BREEDTE", "LENGTE", "DIKTE", "DIAM", "BREEDTE_1", "DIAM_1", "LENGTE_1", "DIKTE_1"}
    For Each oPara As String In ParaToDel
        Try
            Dim param1 As Parameter = oParas.Item(oPara)
            param1.Delete
        Catch
            

        End Try
    Next
End Sub

Public Function iProperty3(oDoc As Inventor.Document, oProp As String) As Inventor.Property
    Dim oPropsets As PropertySets = oDoc.PropertySets
    Dim oPropSet As PropertySet = oPropsets.Item("{32853F0F-3444-11D1-9E93-0060B03C1CA6}")
    Try
        iProperty3 = oPropSet.Item(oProp) 
    Catch
        oPropSet.Add("", oProp)
        iProperty3 = oPropSet.Item(oProp)
        
    End Try
    oPropsets = Nothing
    oPropSet = Nothing
End Function

Public Function iProperty2(oDoc As Inventor.Document, oProp As String) As Inventor.Property
    Dim oPropsets As PropertySets = oDoc.PropertySets
    Dim oPropSet As PropertySet = oPropsets.Item("{D5CDD502-2E9C-101B-9397-08002B2CF9AE}")
    Try
        iProperty2 = oPropSet.Item(oProp) 
    Catch
        oPropSet.Add("", oProp)
        iProperty2 = oPropSet.Item(oProp)
        
    End Try
    oPropsets = Nothing
    oPropSet = Nothing
End Function

Public Function iProperty(oDoc As Inventor.Document, oProp As String) As Inventor.Property
    Dim oPropsets As PropertySets = oDoc.PropertySets
    Dim oPropSet As PropertySet = oPropsets.Item("{F29F85E0-4FF9-1068-AB91-08002B27B3D9}")
    Try
        iProperty = oPropSet.Item(oProp) 
    Catch
        oPropSet.Add("", oProp)
        iProperty = oPropSet.Item(oProp)
        
    End Try
    oPropsets = Nothing
    oPropSet = Nothing
End Function

Public Function iPropertyUser(oDoc As Inventor.Document, oProp As String) As Inventor.Property
    Dim oPropsets As PropertySets = oDoc.PropertySets
    Dim oPropSet As PropertySet = oPropsets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")
    Try
        iPropertyUser = oPropSet.Item(oProp)
        Catch
            oPropSet.Add("", oProp)
            iPropertyUser = oPropSet.Item(oProp)
    End Try
    oPropsets = Nothing
    oPropSet = Nothing
End Function 


Sub AddRule(oDoc As Inventor.Document)
    
    Dim RuleName As String = "DIMENSIONS Sheet Metal" 'Existing Rule in Design Data folder. Used in standard.ipt as 'execute before saved'
                                
                         
    Dim RuleAlreadyExists As Boolean = False
    ' Define the iLogic addin
    Dim iLogicAddIn As ApplicationAddIn = ThisApplication.ApplicationAddIns.ItemById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}")
    ' Get the iLogic automation object
    Dim iLogic As Object = iLogicAddIn.Automation
    ' Get the list of iLogic rules in the current Inventor document
    Dim RuleList As Object = iLogic.Rules(oDoc)
    
    ' Loop through all rules in document
    For Each R As Object In RuleList
        If R.Name = RuleName Then
            ' A rule with the same name already exists...
            RuleAlreadyExists = True
            Exit For
        End If
    Next
    
    If RuleAlreadyExists Then
        Dim ReplaceRule As MsgBoxResult = MsgBox("A rule called '" & RuleName & "' already exists - replace it?", 36, "Excitech iLogic")
        If ReplaceRule = vbYes Then
            ' Delete the existing rule
            iLogic.DeleteRule(oDoc, RuleName)
            ' Add the new rule
            iLogic.AddRule(oDoc, RuleName, RuleText)
        Else
            MsgBox("Operation cancelled...", 64, "Excitech iLogic")
            Exit Sub
        End If
    Else
        ' No existing rule to delete - simply add the new rule
        iLogic.AddRule(oDoc, RuleName, RuleText)
    End If
    
    ' End of iLogic rule =================================================
End Sub


 

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
0 Likes
Message 9 of 13

Owner2229
Advisor
Advisor

In the AddRule you don't have the RuleText variable defined. A tip here, if you want to skip to new row, use one of these in text:

vbNewLine

vbLf

 

Since you're using almost all of the iProSets, you can simplify it like this:

 

Public Function iProperty(oDoc As Inventor.Document, oSetName As String, oProp As String) As Inventor.Property
    Dim oSetClass As String = {D5CDD505-2E9C-101B-9397-08002B2CF9AE} 'Custom by default
Select Case oSetName
Case "Project": oSetClass = "{F29F85E0-4FF9-1068-AB91-08002B27B3D9}"
Case "Summary": oSetClass = "{D5CDD502-2E9C-101B-9397-08002B2CF9AE}"
Case "Design": oSetClass = "{32853F0F-3444-11D1-9E93-0060B03C1CA6}"
End Select
Dim oPropsets As PropertySets = oDoc.PropertySets Dim oPropSet As PropertySet = oPropsets.Item(oSetClass) Try iProperty = oPropSet.Item(oProp) Catch oPropSet.Add("", oProp) iProperty = oPropSet.Item(oProp) End Try oPropsets = Nothing oPropSet = Nothing End Function

Notice, there's no need to add Custom in the Select Case as it is Custom by default, so when oSetName is something unknown it will stay Custom.

 

And use it like:

 

iProperty(oDoc, "Design", "Creation Time").Value = Now()
iProperty(oDoc, "", "VLDS_Profile").Value        = "RELCO US JO PART"
iProperty(oDoc, "Summary", "Manager").Expression = ""

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 10 of 13

machiel.veldkamp
Collaborator
Collaborator

Hey @Owner2229

 

Thanks again. 

 

The AddRule() is something I found online somewhere. I actually have a Rule that's authorized by the Admin and is in the Standard.ipt that I wanted to inject into each ipt I find. (the older ipt don't have those)

 

I was hoping to modify this code to fit my need. 

 

It looks like it doesn't though. So far I haven't been able to find any way to add an existing Rule to a ipt through iLogic. 

 

I wanted to put it in the Triggerlist "before a save" and "When the geometry changes" 

 

Am I missing something or is that just not possible?

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
0 Likes
Message 11 of 13

MechMachineMan
Advisor
Advisor

You should be able to work with this for copying rules over. To get RuleText I just grab it from the source document.

 

See more about the documentation for iLogic calls here:

       https://forums.autodesk.com/t5/inventor-customization/ilogic-api-documentation/td-p/6785772

 

Sub Main()

      Dim oDoc As Document = ThisApplication.ActiveDocument
      Dim oTemplateDoc As Document = ThisApplication.Documents.Open("C:\Users\Owner\Desktop\SourceDoc.ipt", True)

      oAuto = iLogicVb.Automation

'To Copy a specific rule over only
'[
	CopyRuleToDoc(oDoc, oAuto.GetRule(oTemplateDoc,"Rule0"))
	CopyRuleToDoc(oDoc, oAuto.GetRule(oTemplateDoc,"Rule1"))
']
	
'To copy all rules over:
'[
'      For Each oRule In oAuto.Rules(oTemplateDoc)
'	  	  MsgBox(oRule.Name)
'         CopyRuleToDoc(oDoc, oRule)
'      Next
']
      oTemplateDoc.Close(True)

End Sub

Dim oAuto As Object

Sub CopyRuleToDoc(DestinationDoc As Document, oRule As Object)
    oAuto.AddRule(DestinationDoc, oRule.Name, oRule.Text)	
End Sub

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 12 of 13

machiel.veldkamp
Collaborator
Collaborator

Wohoooo. 

 

 

So wait. You can change the ilogic inside the ipt with the Inventor API? 

Oh man. I'm gonna read that document so hard. Thanks for that and all the rest

 

 

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
0 Likes
Message 13 of 13

MechMachineMan
Advisor
Advisor

Certainly. If you really want to dive into the rabbit hole, you can set your event triggers with iLogic as well.

 

Sub Main()
	
	Dim EventPropSet As Inventor.PropertySet
	EventPropSet = GetiLogicEventPropSet(ThisApplication.ActiveDocument)
	
	Call ListiProps(EventPropSet)
	
	'Call PurgePropSet(EventPropSet)
	
	EventPropSet.Add("Rule0", "BeforeDocSave0", 700)
	
	EventPropSet.Add("Rule0", "PartBodyChanged0", 1200)
	'EventPropSet.Add("Rule2", "PartBodyChanged1", 1201)
	
	Call ListiProps(EventPropSet)
	
End Sub

Function GetiLogicEventPropSet(cDocument As Document) As Inventor.PropertySet
	On Error Resume Next
		iLogicEventPropSet = cDocument.PropertySets.Item("iLogicEventsRules")
		
		If iLogicEventPropSet Is Nothing Then
			iLogicEventPropSet = cDocument.PropertySets.Item("_iLogicEventsRules")
		End If
		
		If iLogicEventPropSet.InternalName <> "{2C540830-0723-455E-A8E2-891722EB4C3E}" Then
			Call iLogicEventPropSet.Delete
			iLogicEventPropSet = cDocument.PropertySets.Add("iLogicEventsRules", "{2C540830-0723-455E-A8E2-891722EB4C3E}")
		End If
		
		If iLogicEventPropSet Is Nothing Then
			iLogicEventPropSet = cDocument.PropertySets.Add("iLogicEventsRules", "{2C540830-0723-455E-A8E2-891722EB4C3E}")
		End If
		
		If iLogicEventPropSet Is Nothing Then
			MsgBox ("Unable to create the Event Triggers property for this file!", , "Event Triggers Not Set")
			Err.Raise(1)
			Exit Function
		End If
	On Error Goto 0
	
	Return iLogicEventPropSet
End Function

Sub ListiProps(iPropSet As Inventor.PropertySet) 	
	oStr = "PROPSET: " & Chr(34) & iPropSet.DisplayName & Chr(34) & " -- " & iPropSet.InternalName
	For j = 1 To iPropSet.Count
		oStr = oStr & vbLf & j & ")" & iPropSet(j).Name & " - " & iPropSet(j).Value & " -- " & iPropSet(j).PropID
	Next
	MsgBox(oStr)
End Sub

Sub PurgePropSet(iPropSet As Inventor.PropertySet)
	For j = iPropSet.Count To 1 Step - 1
		iPropSet(j).Delete
	Next
End Sub

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes