A Bit (or a Lot) of Help Please

A Bit (or a Lot) of Help Please

simon4D86F
Enthusiast Enthusiast
1,711 Views
25 Replies
Message 1 of 26

A Bit (or a Lot) of Help Please

simon4D86F
Enthusiast
Enthusiast

Hi everyone,

 

I have asked a couple of "Experts the same question, but no joy so I am throwing this out to the community for any help I can get. 

 

I hope you can help me out here, I have been searching the forums for an answer to a problem that I have created and want to solve, but I think that this means going into the API which is another minefield. 

 

I have found some possible partial solutions, but they do not really work for what I am trying to achieve and being new to ilogic, find myself going around in circles. So if you can help me, my problem is below...

 

I want to set up a rule that will "Inspect" each part within an assembly, check to see if it has a cut out, hole, slot, bevel etc and then make sure that the corresponding description is in the Custom iProperties and if not, put it there.

 

I also need this to run on any assembly, no assemblies with an assembly included and never more than 15 parts within that assembly and all of the parts are a minimum of 15mm thick

 

Lets say I have an assembly, and within that assembly I have....

1 part has a Radius on a corner, that would be placed into a custom iproperty "Desc2" as "Rout/"

1 part has a Chamfer or extrusion on a corner, that would be placed into a custom iproperty "Desc2" as " "Bevel/"

1 part has a Hole up to 10mm in the part, that would be placed into a custom iproperty "Desc2" as "Drill/"

1 part has a Hole larger than 10mm in the part, that would be placed into a custom iproperty "Desc2" as "Rout/"

1 part has a iFeature or Punch Tool in the part, that would be placed into a custom iproperty "Desc2" as "Slot/"

1 part has a Extruded cutout in the part, that would be placed into a custom iproperty "Desc2" as "Rout/"

1 part has a nothing (other that width thickness and depth), that would be leave the "Desc2" in iProperties as blank

 

As I have said, I have searched the forums and cannot find anything that really helps other than sending me around in circles, or it may simply be not asking the right question,

 

I dont know if I am explaining myself very well, so please let me know if not.

 

If you could help, I would be most grateful.

 

Oh, one other thing, I work away from home so only get to do this at the weekends so any replies from me will be late in most cases, so apologies in advance.

 

Many thanks in advance for your time  and effort.

 

Simon

0 Likes
1,712 Views
25 Replies
Replies (25)
Message 2 of 26

clutsa
Collaborator
Collaborator

This will get you started...

Dim app As Inventor.Application = ThisApplication
Dim doc As AssemblyDocument = app.ActiveDocument
Dim compDef As ComponentDefinition = doc.ComponentDefinition
Dim Occ As ComponentOccurrence
For Each Occ In compDef.Occurrences
	Dim PDoc As PartDocument = Occ.Definition.Document
	'Dim PartFeatures As Features = PDoc.ComponentDefinition.Features
	Dim Desc2 As String
	For Each Feat In PDoc.ComponentDefinition.Features
		'your code to look for features and fill in Desc2
		Desc2 = "Changed" 'this will change based on your code
	Next
	
	'after feature is found
	If PDoc.PropertySets("Inventor User Defined Properties").Item("Desc2") Is Nothing Then
		PDoc.PropertySets("Inventor User Defined Properties").Add(Desc2, "Desc2")
	Else
		PDoc.PropertySets("Inventor User Defined Properties").Item("Desc2").Value = Desc2
	End If
Next
If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 3 of 26

philip1009
Advisor
Advisor

There are a lot of steps take for this rule to basically scan down through every feature and if necessary every sketch feature.  The main dependent is how the parts are designed, if everything is driven by sketches, it'd be insanely difficult or probably impossible to determine if a curve in a sketch is for a hole, a slot, a round, etc.

 

For best practice, I'd recommend you make sure they're used in specific features, i.e. always use the round or chamfer tool instead of using a sketched extrusion to make the same feature.

 

This way you can track by the features of the part to determine your iProperties instead of going through sketches.

 

It looks like it's all going to one Custom iProperty with a / to denote each manufacturing step.  Is this going to be the case in the final rule?

 

0 Likes
Message 4 of 26

simon4D86F
Enthusiast
Enthusiast

Hi Philip 1009,

None of the options are covered by sketches, everything is done by the Fillet tool, Hole tool etc.

0 Likes
Message 5 of 26

clutsa
Collaborator
Collaborator

Here's a bit more help (maybe)

Dim app As Inventor.Application = ThisApplication
Dim doc As AssemblyDocument = app.ActiveDocument
Dim compDef As ComponentDefinition = doc.ComponentDefinition
Dim Occ As ComponentOccurrence
For Each Occ In compDef.Occurrences
	Dim PDoc As PartDocument = Occ.Definition.Document
	Dim Desc2 As String
	For Each Feat In PDoc.ComponentDefinition.Features
		Select Case Feat.Type 
		Case = ObjectTypeEnum.kHoleFeatureObject
			Desc2 = "Drill/"
		Case = ObjectTypeEnum.kFilletFeatureObject
			Desc2 = "Rout/"
		Case = ObjectTypeEnum.kChamferFeaturesObject
			Desc2 = "Bevel/"
		'Case = you get the idea
		End Select
		'Note: this will only record the last feature if you want to make a sting of all the steps use _
		'Desc2 = Desc2 & "Whatever/" then you'll get Drill/Rout/Bevel in the end
	Next
	
	'after feature is found
	If PDoc.PropertySets("Inventor User Defined Properties").Item("Desc2") Is Nothing Then
		PDoc.PropertySets("Inventor User Defined Properties").Add(Desc2, "Desc2")
	Else
		PDoc.PropertySets("Inventor User Defined Properties").Item("Desc2").Value = Desc2
	End If
Next
If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 6 of 26

Frederick_Law
Mentor
Mentor

It will be difficult to check if an extrusion is a chamfer.

Program will see extrusion, won't know if its at corner.

So if someone sketch a profile with radius and chamfer, the program will not see them.

0 Likes
Message 7 of 26

chandra.shekar.g
Autodesk Support
Autodesk Support

@simon4D86F,

 

Can you please provide assembly which contains all feature mentioned below? Please make sure that files are non confidential.

 

1 part has a Radius on a corner, that would be placed into a custom iproperty "Desc2" as "Rout/"

1 part has a Chamfer or extrusion on a corner, that would be placed into a custom iproperty "Desc2" as " "Bevel/"

1 part has a Hole up to 10mm in the part, that would be placed into a custom iproperty "Desc2" as "Drill/"

1 part has a Hole larger than 10mm in the part, that would be placed into a custom iproperty "Desc2" as "Rout/"

1 part has a iFeature or Punch Tool in the part, that would be placed into a custom iproperty "Desc2" as "Slot/"

1 part has a Extruded cutout in the part, that would be placed into a custom iproperty "Desc2" as "Rout/"

1 part has a nothing (other that width thickness and depth), that would be leave the "Desc2" in iProperties as blank

 

It would be convenient to test all features.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 8 of 26

simon4D86F
Enthusiast
Enthusiast

Hello Guys,

 

Many thanks for your help so far, what you have supplied me is outside my understanding at the moment, but I am learning.....

 

Clutsa, your solution works up to a point, I tried various things to include the punch tools, but that was a massive failure, but I will continue to try.

 

 

 

0 Likes
Message 9 of 26

chandra.shekar.g
Autodesk Support
Autodesk Support

@simon4D86F,

 

Sorry for late reply,

 

There is no direct Inventor API to identify slots or cut outs. Suggestion from @clutsa is helpful to a great extent.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 10 of 26

clutsa
Collaborator
Collaborator

Would a tool that looped thru the design tree and highlighted the different features and had a dialog box with all the options (and a skip button) you click to identify each feature work? Then once it was done it would build the string for you. It would need the user to make the call but would probably only take 30 or 40 seconds to do a part.

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 11 of 26

clutsa
Collaborator
Collaborator

The attached doesn't loop thru and highlight the sections but it is a way to quickly build your string.

I had to run it through VBA but I added a rule to call the form so it would be easy to use...(you would have to make a new external rule and add the form to the application project but that's not hard)

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 12 of 26

simon4D86F
Enthusiast
Enthusiast
Hi,

That sounds really interesting, BUT, I am a newby when it comes to iLogic
and from your description, the code must be huge and very likely beyond me,
saying that, the code already supplied is beyond me, but I am getting there
I think, Slowly.

I would very much like to see an example if possible please.

Many thanks

Simon
0 Likes
Message 13 of 26

clutsa
Collaborator
Collaborator

Yep, see my last post. There is a part file you can download that already has the sample in it. just rule "rule0" from the iLogic browser

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 14 of 26

Anonymous
Not applicable

Hi Clutsa,

 

This may be my fault, not sure, but I get the following error message on running the rule. What am I missing?

 

0 Likes
Message 15 of 26

clutsa
Collaborator
Collaborator

Well there's only one line in that rule so that helps narrow it down.Smiley Tongue

If you go to Tools>VBA Editor does your DocumentProject have UserForm1 and Module1?

VBAEditor.PNG

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 16 of 26

Anonymous
Not applicable
Hi Clutsa,

The Line reads.... "InventorVb.RunMacro("DocumentProject", "Module1", "
ShowForm")"
Running Inventor Pro 2018 just in case that is causing a problem.
0 Likes
Message 17 of 26

clutsa
Collaborator
Collaborator

I too am running Inv Pro 2018 so that shouldn't be it.

This uses VBA to work so you have to open the VBA Editor under tools.

VBAEditor2.PNG

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

Message 18 of 26

Anonymous
Not applicable

Sorry Clutsa,

 

It will teach me to read the actual post and not just the email.  The VBA Editor states "Module1".

Can you give me a breakdown of the code supplied, it appears to be doing a lot for just one line of code?

 

Regards

 

0 Likes
Message 19 of 26

clutsa
Collaborator
Collaborator

If you right click on UserForm1 and click on "View Code" you'll see all the other code. The "Me" in "Me.Label1.Caption" is the UserForm1. I didn't rename all the buttons like I should because I was in a hurry but each button just adds another word to the end of Label1. Button6 does all the real work from there. 

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 20 of 26

Anonymous
Not applicable

Hi Clutsa,

 

I had to laugh when you said "I didn't rename all the buttons like I should because I was in a hurry", if this was done in a hurry, I may as well pack up now.

 

I followed your instructions and viewed the code, which helps, alot, however, a couple of questions or maybe the same one.....

 

When I run the code on just the part only, I now get he following error message....

 

"Error in Rule0, in document:stringBuilderTool.ipt

RunMacro: No VBA macro named "ShowForm" was found in the component or module named "Module1", in the VBA project named "DocumentProject".

 

But when I run the code with the part in an assembly, I get the following Error message....

 

"Error in Rule0, in document: TEST 1.iam

RunMacro: No VBA component or module named "UserForm1" was found in the VBA project named "DocumentProject".

 

I know that the "Showform " and "Module1" are in the code, I looked :-), so what am I doing wrong, 

 

 

 

0 Likes