iLogic rule run from a part wont do work on an assembly it creates

iLogic rule run from a part wont do work on an assembly it creates

espen_olsen
Explorer Explorer
695 Views
3 Replies
Message 1 of 4

iLogic rule run from a part wont do work on an assembly it creates

espen_olsen
Explorer
Explorer

I frequently make a "master" part with multiple bodies that i export into separate parts, and I then insert those part into an assembly. I then import another library part into the assembly.

I have made an iLogic rule for this and it works fine.

 

My problem is I want to have this rule also apply some mates/flush between some of the objects in the assembly, so things end up in the right place automatically.

 

I have managed to make a rule that can do this if I have the assembly open, but if I trigger it from the above mentioned rule to make the whole thing automated it will not run because i get the error message:

Error in rule: MoveLid, in document: 4321-013-001.ipt
ThisAssembly: This document "4321-013-001.ipt" is not an assembly.

The rule I'm using:

Sub Main()
	Dim casename As String = "peli1660"
	'Dim casename As String = RuleArguments("name")
	Dim asm As AssemblyDocument
	asm = ThisApplication.ActiveDocument
	Dim oOccurrence As ComponentOccurrence
	For Each oOccurrence In asm.ComponentDefinition.Occurrences
		If Not TypeOf oOccurrence.Definition Is VirtualComponentDefinition Then
			If oOccurrence.Name.Contains("Lokk")
				oOccurrence.Grounded = False
				Constraints.AddFlush(oOccurrence.Name+"Mate1", oOccurrence.Name, "XY Plane", {casename+":1", "Lokk:1" }, "XY Plane", )
				Constraints.AddFlush(oOccurrence.Name+"Mate2", oOccurrence.Name, "YZ Plane", {casename+":1", "Lokk:1" }, "YZ Plane", )
				Constraints.AddFlush(oOccurrence.Name+"Mate3", oOccurrence.Name, "XZ Plane", {casename+":1", "Lokk:1" }, "XZ Plane", )
			End If
		End If
	Next
End Sub

"Constraints.AddFlush..." is the line(s) that cause troubles.

 

Is there a way to make this work if I start the whole thing from a part file?

0 Likes
696 Views
3 Replies
Replies (3)
Message 2 of 4

JelteDeJong
Mentor
Mentor

Hi,

You did not share the rule in the part so i have to guess a bit. I expect that the problem already start in the line:

asm = ThisApplication.ActiveDocument

The property "ThisApplication.ActiveDocument" can be refrencing the part file instead of the new assembly. But i expect that there is a line (in the rule of the part) that creates the assembly that looks like this:

Dim oAssembly = ThisApplication.Documents.Add(DocumentTypeEnum.kAssemblyDocumentObject)

because "oAssembly" is refrencing the assembly for sure you should use that object for the rule of your assembly.

I did not see if you start the assmbly rule from the part rule or if you want to merge the 2 rules. I guess that you want to merge the 2 rule. In that case its easy just replace "asm = ThisApplication.ActiveDocument" with "asm = oAssembly" (or what ever oAssembly is called in your part rule)

 

if this does not help then plz also post the rule in your part.

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 4

J-Camper
Advisor
Advisor

If you want to use this rule as is, make sure you Activate or Open the Assembly Document before calling the rule to run.  Without the rule you are running in the part, it's hard to know what have already tried. 

 

However, if the rule truly is making it into the Occurrence loop, which it would not be able to do for a part file, then you do have the Assembly Document Active but you might not be able to use the Shorthand Syntax "Constraints".  In which case you could try spelling out the Syntax in more detail, AssemblyConstraints Object Documentation 

 

0 Likes
Message 4 of 4

espen_olsen
Explorer
Explorer

Before I run the rule in my original post, in the original rule, I do asm.Activate. This makes the assembly become the document thats currently being displayed on the screen, so I think there shouldnt be a problem, unless I misunderstand what exactly "ThisApplication.ActiveDocument" is actually referencing.

 

Also the rule seems to work besides "Constraints.AddFlush..."

oOccurrence.Grounded = False

This line also seems to work, and gets executed on the right object and only if it is supposed to.

I also tried adding another line inside the final if statement:

MessageBox.Show(asm.DisplayName)

 And this one shows the name of the assembly.

 

To me it seems that this is a bug/feature where it doesnt update what sort of document you are currently working on for some commands.

 

I did try to use AssemblyConstraints.AddFlushConstraint, and that line seems to work, but I ran into the above mentioned problem trying to make objects for the planes I wanted to stitch together, so I figured there is somethign more fundamentally wrong with my rule, and thats when I made this post as I couldnt find anyone else mentioning this problem. Maybe it will work if I spell out the syntax a bit more like JCamper suggests, but after thinking abit about it overnight I figured out a simpler way to do it on friday.

 

I have now made an event trigger that runs this rule every time I save an assembly file. I dont really want to run this rule everytime I save an assembly though, but I rebuilt the rule a bit so it my first rule adds a parameter to the assembly that indicates weather or not the rule should be run, and then the second rule basically checks if it should actually do anything.

 

Thanks for the replies though!

 

Ill add the "main" rule as an attachment if it is still interesting, as its quite long, and also somewhat messy.

The original rule I posted is called "MoveLid" and is ran at the very end of the main method.

 

0 Likes