Custom Parameter / Part Name

Custom Parameter / Part Name

emanuel.c
Collaborator Collaborator
1,187 Views
9 Replies
Message 1 of 10

Custom Parameter / Part Name

emanuel.c
Collaborator
Collaborator

I would much appreciate some support. I suppose I could pay someone to help me out, but I don’t just want the job done, I would like to learn iLogic also. I need to create an internal Part Number for our company. The code would run at an Assembly level over all parts included, but it isn’t needed for assemblies / sub-assemblies.

 

The part number is composed of various digits that have certain meanings. Best would be to populate these from an Excel spreadsheet and it would be better to have it as an external rule, in case changes would be needed, they’d be easier to implement. It is a 14-digit part number.

 

  1. The first digit is material type. This I would pull from the iProperty.Material. For ex: 1 (for steel), 2 (for stainless steel) etc.
  2. Digit 2,3 has the shape type of the part. For the content center parts I would add a text user parameter called “Shape” in the family template file, which would be filled in accordingly. In the code I would need to verify if the user parameter “Shape” exists and add those corresponding 2 digits to the Part Name. For example if Shape=”Sq Tube”, then digit 2,3 should be 01. If it doesn’t exist it would need to open a message box with a drop down list to add it. Is it difficult to do this for many parts? Is there an easier way to do it? Can I attribute the digits by fetching the family name of the shape?
  3. Digit 4,5,6 refer to one of the dimensions of the shape. For box tubing, for example, I would pull it from the “G_W” value. For Pipe, from the “Diam” value. For sheet metal it would be “Thickness” (all without dots of course).
  4. Digit 7,8,9 are a second dimension of the part, like “G_H” or one side of the flat pattern of the sheet metal.
  5. Digit 10-13 are a third dimension of the part. For sheet metal it would be the other side of the flat pattern extent.
  6. Digit 14 is for an optional entry. I would have to write a new text user parameter to each part called “Opt_Digit” in case it would need to be populated. If that is left empty, then by default the new Part Number would write in “0” for the last digit. If it is populated, it would write in that digit. The space for the parameter “Opt_Digit” can only be 1 though.

I realize it’s a high tally, but if anyone wishes to help, I would be very grateful. Maybe there are better ways to accomplish this altogether, I don’t know. Meanwhile, I’ll keep stabbing at this thing as I can.

Thank you much!

0 Likes
Accepted solutions (2)
1,188 Views
9 Replies
Replies (9)
Message 2 of 10

A.Acheson
Mentor
Mentor

Just looking at what makes up the part number there is a lot going to have to be learned regarding detection of document types, content center family types, parameters, part size and a lot of variables that will have to be decided in advance  It may take some time to be able to learn this complexity of programming I would think at least a year plus would be the experience you may need. But with the help of others you might be able to get there sooner. I am curious as how you have implemented this type of part number thus far without iLogic generating it?

 

Is the purpose of the excel sheet simply to track the part number after it has been created via iLogic? Or will the user use this to manually type in the part number? 

 

In our company we use an inventory software to generated our part numbers and we really don't use the meaning of the part number to great effect relying mainly on the description.

 

Since your new to iLogic I have put together a very simple example of how 2 items might work material and optional entry.

Dim oMaterial As String

If iProperties.Material = "Steel"
	oMaterial = "1"
ElseIf iProperties.Material = "Stainless Steel"
	oMaterial = "2"
End If
 
 Dim oOptional As String
 oOptional = InputBox("Prompt", "Title", "Default Entry")
 
 Dim Partnumber As String
 
 Partnumber = oMaterial & oOptional
 
 MessageBox.Show(Partnumber, "Title")

Hopefully other users might jump in also with other ideas.

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 10

emanuel.c
Collaborator
Collaborator

Thank you so much for the support! Yes I realize it will take significant amount of time but I want to learn.

 

The company has recently began using a software which incorporates everything from sales, to job tracking, parts, invoices etc. This part number is not for the technical drawings but for this software. Since it's relatively new we enter in this part number manually but it isn't a sustainable solution.

 

Actually, it may not need Excel at all, but it seems to me it should run as an external rule so I could tweak the code should I need to in the future and not have to deal with all kinds of code in all kinds of assemblies.

 

Thanks again!

0 Likes
Message 4 of 10

Michael.Navara
Advisor
Advisor
Accepted solution

This task is very complex and it will cost a lot of your time. If you want to learn iLogic, I prepare for you the first approach to your described task. But it requires some knowledge of "object oriented programming" (OOP) and deep knowledge of Inventor properties, parameters, content center, etc. In attachment is iLogic code and some files for your testing. I recommend you to use VisualStudio for testing and debugging, because you can use breakpoints and inspection capabilities of VS for better understanding what happens.

See here for more info: https://modthemachine.typepad.com/my_weblog/2019/12/using-visual-studio-to-debug-ilogic-rules.html

 

 

Message 5 of 10

A.Acheson
Mentor
Mentor

@emanuel.c 

You are correct in thinking an external rule is what you need. regarding excel you won't need this unless you are storing data in the excel sheet to make up your part number. But it would be best to store that in the code where possible to reduce loading delays. 

 

Here is a link to some iLogic articles. 

https://www.autodesk.com/autodesk-university/au-online?query=ilogic&_ga=2.2461561.810972916.16289755...

 

And here is how to access the built in API help.

 

AAcheson_0-1629075922643.png

 

 

Between this and internet browsing you should be well on your way. I think I have approx. 800 links saved between you tube clips, online articles and forum post not to mention countless others over my 2 year learning experience. Really you have to start with a basic item like document and started familiarizing yourself with there methods and samples.  I would have done this the opposite way and look at the samples first on the forum and ran them on documents based on the functionality users were looking to achieve. But this can be not good practice at times because you might miss learning opportunities creating from scratch.

 

 

Example of document search, critical for accessing drawing, parts and assembly.

 

AAcheson_1-1629076101859.png

 

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 6 of 10

emanuel.c
Collaborator
Collaborator

Hello Michael,

 

Thank you very much for helping out! It seems like a lot to me, but maybe for a pro it isn't as difficult. I try to run the rule, but I get a lot of errors. Does it work for you?

 

Capture.JPG

 

0 Likes
Message 7 of 10

Michael.Navara
Advisor
Advisor

My code works well, but it is designed for testing on individual parts. You need to open part document and run the rule. For use in assembly, you need to modify the Sub Main and get some part document. For example

 

From:

Sub Main()
   Dim part As PartDocument = ThisDoc.Document
   Dim fileNumber As String = GetFileNumber(part)
   Logger.Info(fileNumber)
End Sub

To:

Sub Main

	Dim activeDoc As Document = ThisDoc.Document
	Dim part As PartDocument

	If activeDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
		PrintFileNumber(activeDoc)
	ElseIf activeDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
		Dim asm As AssemblyDocument = activeDoc
		For Each referencedDoc As Document In asm.AllReferencedDocuments
			If referencedDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
				PrintFileNumber(referencedDoc)
			End If
		Next
	End If
End Sub

Sub PrintFileNumber(part As PartDocument)
	Dim fileNumber As String = GetFileNumber(part)
	Logger.Info(fileNumber)
End Sub

 

0 Likes
Message 8 of 10

emanuel.c
Collaborator
Collaborator

Thank you so much for your help! I'll use some of it and tweak as needed. I have some things working.

0 Likes
Message 9 of 10

emanuel.c
Collaborator
Collaborator

I slightly misunderstood the need for this iProperty I'm working on. It's not a part name but it rather should correlate to the stock number in our company software. Therefore it doesn't need quite as many digits and it isn't quite as complicated. With what you began I managed to put it together and the code works ok. However, I'm sure it could be written better or for more efficient functioning. If you see fit and have the time to point out any issues feel free to do that.

 

The bigger issue now is how to have all the "CASES" pull data from Excel. And maybe I can have the company software also relate to that spreadsheet, though I haven't looked at it closely yet. I think that was entered manually, but I'm sure it has a data base behind it.

 

If someone could help me with one of them, I will be good to go with the rest. Very grateful!

0 Likes
Message 10 of 10

emanuel.c
Collaborator
Collaborator
Accepted solution

Thank you to both for helping out! It's been fun and amazing to see it working! Couldn't have done it without your help.

 

Here is the completed project just in case someone else can use any part of this. The content center file templates are edited to include their particular iProperty "Product" and an Excel Spreadsheet is where the iLogic pulls information from.