Creating Custom property to subassemblies

Creating Custom property to subassemblies

vkulikajevas
Advocate Advocate
534 Views
4 Replies
Message 1 of 5

Creating Custom property to subassemblies

vkulikajevas
Advocate
Advocate

I am trying to push this PROP01, from input box into all subassemblies. Can someone help me to make an ilogic rule code? 

 

PROP01 = InputBox("Property01", "Title", "")
iProperties.Value("Custom", "Property01") = PROP01	

 

0 Likes
Accepted solutions (2)
535 Views
4 Replies
Replies (4)
Message 2 of 5

A.Acheson
Mentor
Mentor

How deep do you want to go with the sub assemblies. All on first level or all sub assemblies in the assembly regardless of how deep? 

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 5

vkulikajevas
Advocate
Advocate
Hello, A.Acheson. Though all subassemblies.
0 Likes
Message 4 of 5

vkulikajevas
Advocate
Advocate
Accepted solution

After digging and modifying several codes, I was able to make it work. Maybe someone will need this too. Code bellow:

 

'UPDATE project, FileNumber,
On Error Resume Next
'PROP01 = InputBox("Property01", "Title", "")
PROJECT = InputBox("Project", "Enter Project", "")

Dim FullFileName, FileName, PartNumber As String
Dim FNamePos As Long
'set a reference to the assembly component definintion
Dim asmDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oDoc As Inventor.Document
Dim asmDef As AssemblyComponentDefinition
asmDef = asmDoc.ComponentDefinition

'----Prevent message
If MsgBox("This will update Parameters in all sub files (in this model)" _
& vbNewLine & "Do you wish to Continue ?", vbYesNo + vbQuestion, "iLogic") = vbNo Then Return

'Store referenced documents properties
For Each oDoc In asmDoc.AllReferencedDocuments
    FullFileName = oDoc.FullFileName 'With extension
	'---Find last "\" position in full filename path string   
    FNamePos = InStrRev(FullFileName, "\", - 1)
    '---Extract FileName 
    FileName = Mid(FullFileName, FNamePos + 1, Len(FullFileName) - FNamePos)
    PartNumber = Left(FileName,Len(FileName) - 4) 'Without extension
    iProperties.Value(FileName, "Project", "Part number") = PartNumber
	
	iProperties.Value(FileName, "Project", "Project") = PROJECT
	'iProperties.Value(FileName, "Custom", "Property01") = PROP01


	
Next

iProperties.Value("Project", "Project") = PROJECT
'iProperties.Value("Custom", "Property01") = PROP01 ' this assembly

 

0 Likes
Message 5 of 5

WCrihfield
Mentor
Mentor
Accepted solution

I was just about to post a solution using the original iProperty you mentioned, then saw that you posted a different solution.  So, I decided to just give you a tip about the solution you posted that may help you in the future.  There are many ways to manipulate String values, and there have been many code combinations for isolating parts of file names, but I believe that the methods defined within the System.IO.Path hierarchy of the vb.net system will likely return the most stable results for this purpose and help reduce more lines of code.  So I made an alternate version of your last solution that uses the appropriate lines of code from that area to show you how they can be used to simplify this task.

'UPDATE project, FileNumber,
PROJECT = InputBox("Project", "Enter Project", "")
'set a reference to the assembly component definintion
Dim asmDoc As AssemblyDocument = ThisApplication.ActiveDocument
'----Prevent message
If MsgBox("This will update Parameters in all sub files (in this model)" _
& vbNewLine & "Do you wish to Continue ?", vbYesNo + vbQuestion, "iLogic") = vbNo Then Return

'Store referenced documents properties
For Each oDoc As Document In asmDoc.AllReferencedDocuments
	'get file name, without path, but with file extension
	oFileName = System.IO.Path.GetFileName(oDoc.FullFileName)
	'get file name, without path, and without file extension
	oPartNumber = System.IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName)
    iProperties.Value(oFileName, "Project", "Part number") = oPartNumber
	iProperties.Value(oFileName, "Project", "Project") = PROJECT
Next

'writes to the 'active' document
iProperties.Value("Project", "Project") = PROJECT

Wesley Crihfield

EESignature

(Not an Autodesk Employee)