Automatic add rule

Automatic add rule

ChristianAndersenIsmyname
Advocate Advocate
812 Views
7 Replies
Message 1 of 8

Automatic add rule

ChristianAndersenIsmyname
Advocate
Advocate

Is it possible to make a external rule that adds rules to a file?

For example:

I have some newly made rules in my .iam and .ipt template that I want to add to existing parts/assemblys. Can I somehow make a external rule that does something like:

 

iLogicVb.AddRule("Template.iam", "Find Part")         '-- Notice AddRule instead of RunRule
iLogicVb.AddRule("Template.iam", "Write")
'-- etc

 

Uten navn.png

 

The same thing for forms. I know I can copy and paste forms, but it would be easier to do this within the same external rule.

Or would my best way to achieve this be template swap on existing parts?

0 Likes
Accepted solutions (1)
813 Views
7 Replies
Replies (7)
Message 2 of 8

JhoelForshav
Mentor
Mentor

Hi @ChristianAndersenIsmyname 

I haven't tried it but I think something like this should work? 🙂

 

Sub CopyRule(copyFromDoc As Document, oRuleName As String, CopyToDoc As Document)
	Dim oRuleText As String = iLogicVb.Automation.GetRule(CopyFromDoc, oRuleName).Text
	iLogicVb.Automation.AddRule(CopyToDoc, oRuleName, oRuleText)
End Sub
0 Likes
Message 3 of 8

ChristianAndersenIsmyname
Advocate
Advocate

Hi Jhoel,

I can't get your code to work. Is it iLogic or VBA?

 

I've tried to "fix" it, and the closest I've come to is this:

	Dim CopyFromDoc As String
	Dim CopyToDoc As String
	Dim oRuleName As String
	
	CopyFromDoc = "K:\04. R&D\3D MODELING\STYLES\Templates\Standard.iam" 'Template
	CopyToDoc = ThisDoc.PathAndFileName(False)
	oRuleName = "Write"
	
	Dim oRuleText As String	
	
	oRuleText = iLogicVb.Automation.GetRule(CopyFromDoc, oRuleName).Text
	iLogicVb.Automation.AddRule(CopyToDoc, oRuleName, oRuleText)

 

I had to change Copyfromdoc as document → string. It stopped at this sentance if it was document.

Now it stops at "oRuleText", which I believe is caused by Copyfromdoc is not a document.

0 Likes
Message 4 of 8

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @ChristianAndersenIsmyname 

It's a sub that I thought you can use in ilogic. Like this maybe?

 

Sub Main
Dim ruleDoc As Document = ThisApplication.Documents.Open("K:\04. R&D\3D MODELING\STYLES\Templates\Standard.iam", False)
CopyRule(ruleDoc, "Write", ThisDoc.Document)
End Sub

Sub CopyRule(copyFromDoc As Document, oRuleName As String, CopyToDoc As Document)
	Dim oRuleText As String = iLogicVb.Automation.GetRule(CopyFromDoc, oRuleName).Text
	iLogicVb.Automation.AddRule(CopyToDoc, oRuleName, oRuleText)
End Sub

 

Message 5 of 8

ChristianAndersenIsmyname
Advocate
Advocate

This works perfectly! Thank you.

Is it possible to make a same one for Forms?

0 Likes
Message 6 of 8

JhoelForshav
Mentor
Mentor

Sorry @ChristianAndersenIsmyname , I don't think thats possible.

It's been discussed before here:

https://forums.autodesk.com/t5/inventor-forum/copy-ilogic-form-via-api-to-several-documents/td-p/543...

And it seems like the way to go is global forms...

0 Likes
Message 7 of 8

ChristianAndersenIsmyname
Advocate
Advocate

Ah ****. Thanks for you help anyway! 🙂

0 Likes
Message 8 of 8

robertast
Collaborator
Collaborator

so it is convenient to copy the form without a rule

Forma.png