Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic from template assy to copy design assy

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
Anonymous
968 Views, 4 Replies

iLogic from template assy to copy design assy

Hello,

 

I'm new to this discussion group and new to iLogic.

The story: we made up an assembly template to help us with our design and inside that template I made up some basic iLogics. We want to control the size of specific parts based on material thickness and some other parameter. I made it using parameters in specific components and making them equal to a certain value minus material thickness. But after the copy design, the name of the parts (components) change and the iLogic is useless.....unless it is done so it looks for part of the component name (which stays the same), gets the parameter in question and makes equal again to a certain value minus material thickness....I don't know how to make this advanced iLogic...

'updates Part 1 Thickness according to material thickness
Parameter("Template Part 1:1", "Thickness")= (1.950 in - Mat_Thickness) + .015 in

'makes Part 2 Thickness equal to Part 1 Thickness
Parameter("Template Part 2:1", "Thickness") = (1.950 in - Mat_Thickness) + .015 in

 Above it is an example of what I've done. The "Template" part of the name changes after the copy design. The "Part 1" or "Part 2" stay the same. Any idea how to look for the part with a certain name, get the parameter and make it equal to something or to another parameter from another component?

 

Thanks,

 

Formcast

4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: Anonymous

I found this code that looks for files in an assembly, but I need iLogic to look for a certain file name and change a parameter in that file based on the above equation.

 

Here is the code:

 

Dim openDoc As Document
openDoc = ThisDoc.Document
Dim docFile As Document

'look at all of the parts in the assembly
For Each docFile In openDoc.AllReferencedDocuments
'get the part file names
Dim FNamePos As Long
FNamePos = InStrRev(docFile.FullFileName, "\", -1)   
Dim docFName As String
docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos) 

 Any idea how iLogic can search for a file name containing "Part 1"?

 

Thanks!

Message 3 of 5
cwhetten
in reply to: Anonymous

Hi and welcome to the forum!

 

The first code you posted sets the value of a parameter in an assembly component:

 

Parameter("Template Part 2:1", "Thickness") = ...

This bit of the code "Template Part 2:1" is the name of the component in the assembly.  Usually, when you insert a component into an assembly, the component name is based on the file name, with a colon and a number appended to represent the instance number (the first component placed is :1, the second identical component gets :2, etc.).

 

It is possible to manually edit the component name to be whatever you like.  When you manually edit the component name, it stays, even if the filename changes.  To take care of the issue you are having (if I understand your question correctly), simply rename the components in your assembly.

 

To edit a component's browser name, click on the component in the browser once, wait a second, then click it again (don't double-click it).  Then type the desired name of the component and press enter.

 

One trick we do so that we know whether or not a component has been renamed in the browser, is to add an underscore to the beginning of the component name.  You will want to manually rename each component in an assembly that is called out in an iLogic rule.

 

Edit:  Here is a picture showing how to rename the component:

 

Component Name.png

 

Please click "Accept as Solution" if this response answers your question.

 

Cameron Whetten
Inventor 2012

Message 4 of 5
Anonymous
in reply to: cwhetten

Hi Cameron,

 

And thank you for the greetings and the quick response.

I've done some "digging" and I found something that works close to what I need. Here is a sample:

 

'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	
		
'format  file name		
Dim FNamePos As Long
FNamePos = InStrRev(docFile.FullFileName, "\", -1)		         
Dim docFName As String
'returns file name with extension
docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos) 


If docFName.Contains("Part_Name") Then
  
Parameter(docFName, "Thickness") = Mat_THK + .500 in

End If
End If

Next

End If
ThisDoc.Document.Rebuild()

 What I was looking for is the docFName.Contains and then I can search for files with specific names and change the required parameter based on the material thickness. I'm getting there! Small steps, but I'm getting there! This Discussion Group helped me a lot!

ButSmiley Frustrated, I have file names in my assembly (by the way, I need my component name to be the same with the file name) that contains "Part_Name" plus some other name, so then all files containing "Part_Name" would have the parameter "Thickness" controlled by this rule. For example: Part_Name_Left.ipt, Part_Name_Right.ipt, Part_Name_Front_Back.ipt will have their "Thickness" changed by Mat_THK +.5 in.

I can live with that for now, but I still want to be able to "pick" only one component from the assembly and apply the expression to one of its parameters. Do you think it is possible?

 

Thanks!

Message 5 of 5
cwhetten
in reply to: Anonymous

Renaming the component in the browser is by far the best way to go.  But if this method just won't work for you, then I guess you can try something else.

 

We have a scenario where we need to use iLogic to replace a component.  The Component.Replace( ) function requires the filename of the replacement file, so something has to be done besides renaming the component in the browser (although we still rename the component that is being replaced).  When we copy design this template, we usually add a job number to the filename (as a suffix), so our code has to be written to account for this.  Here is what we do:

 

Spoiler

thisdocfilename = ThisDoc.FileName(False) 'without extension
jobnumber = Right(thisdocfilename, Len(thisdocfilename) - 27) '27 is number of characters in_

'template filename "5100_HeadPulleyWithBearings"
PHF012_filename = "6201_SEW_PHF011KF87_TA270" & jobnumber & ".iam"

 

This essentially extracts the suffix from the new filename and adds it to the filename string the in code, so that the rule can find the correct file even if it has been changed.  Of course, this assumes that the filename was changed ONLY by adding a suffix.  If it was changed in any other way, the rule will fail to find the file and return an error.

 

But, the point is, you could use a similar method if the changes to your filenames follow an exact logic that can be captured in the rule.

 

Another method would be to call out the assembly component by item instead of filename or browser name.  This would be done with a line of code similar to this:

 

Spoiler
odoc = ThisDoc.Document.ComponentDefinition.Occurrences.Item(1)

 

This would return the first component in the assembly.  As far as I can tell, the order of items matches the order listed in the browser.  So the first item in the browser is Item(1), the second is Item(2), etc.  You could use this method if the order of items in your assembly is always the same, or at least the items that you need to access are always in the same spot.

 

Please click "Accept as Solution" if this response answers your question.

 

Cameron Whetten
Inventor 2012

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report