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 iProperties

4 REPLIES 4
Reply
Message 1 of 5
reginaldmb
841 Views, 4 Replies

iLogic iProperties

Hi

 

Could some expert out there please assist with this.  Not even the authorised Autodesk resellers and support companies in South Africa could assist....

Question 1

How can I automatically run an external rule in all assemblies an inventor user opens (new or existing). The rule asks the user to rename all parts in the assembly to something that is related to the project number (internal numbers we use). This same rule then updates the .idw and certain iProperties accordingly.

 

I've set it up as an external rule, but when adding an iTrigger it only trigger that rule according to my Itrigger for the assembly in which I've created the iTrigger. What I actually want to achieve is that whenever I open any assembly and just before I close it again, I want this external rule to be triggered. This would force the user to rename all the parts in the tree and prevent sitting with the same file name in different assemblies. This becomes a pain when checking files into Vault

 

Question 2

Below are two external rules I am using to rename part files in an assembly file. As you will see it asks the user to type a new name for each .ipt in the assembly and then saves a new .ipt with the new name or just keep the existing .ipt. The user can also type a new name for the .iam and the rule then updates the .idw of the .iam accordingly. The "Rename Assembly Files.iLogicVb" rule calls the "Rename Browser Nodes.iLogicVb" rule to update the tree.

 

My problem comes when the assembly contains not only .ipt files but also .iam subassembly files. Could you please help me with the code to solve this. The other important thing I want to achieve is to only having to type in a new file name for parts or subassemblies that were added since I've opened the file again. With how I have the code now I have to either type in a new name or select "OK" for every file in the tree. With some assemblies containing over 100 files it takes too long to run through the whole thing before I close the file everytime. I would rather want the rule to only ask me to "accept" or type a new name for the new files added to the assembly. Hope it makes sense??

Sub Main()
Dim Path As String = ThisDoc.Path & "\"
Dim FileChange As Boolean = False

InvDoc = ThisDoc.Document
Dim refDocs As DocumentsEnumerator = InvDoc.AllReferencedDocuments
Dim refDoc As Document


'Dim Path As String = ThisDoc.Path & "\"
Dim oDestinationDoc As DrawingDocument
OldAssemblyName = ThisDoc.FileName(False)
AssemblyName = OldAssemblyName	
	
For Each refDoc in refDocs
'MessageBox.show(refDoc.DisplayName)

'input box to enter new file name
NewFileName = InputBox("What is the new file name for " & refDoc.DisplayName & "?", "New File Name", refDoc.DisplayName)
'NewFileName = InputBox("What is the new file name for " & refDoc.DisplayName & "?", "New File Name", iProperties.Value(refDoc.DisplayName, "Project", "Part Number"))
   
    'if the new file name is blank then use the same name
    If NewFileName = "" Then
        NewFileName = refDoc.DisplayName
		'iProperties.Value(refDoc.DisplayName, "Project", "Part Number") = NewFileName & ".ipt"
    End If
   
    'if the user also types in the extesion then remove the extension.
    If NewFileName.EndsWith(".ipt") = True Then
        NewFileName = NewFileName.substring(0,NewFileName.length-4)
        'MessageBox.show(NewFileName)
    End If
   
    'if there is a change in the name then do the following.
    If refDoc.DisplayName <> NewFileName & ".ipt" Then
        'check to see the file already exist. if it does then replace.
        If System.IO.File.Exists(Path & NewFileName & ".ipt") Then
            Component.Replace(refDoc.DisplayName, Path & NewFileName & ".ipt", True)
			'iProperties.Value(refDoc.DisplayName, "Project", "Part Number") = NewFileName & ".ipt"
		Else
            Dim oldName As String = refDoc.DisplayName
            'if it does not exist then recreate the file
            refDoc.saveas(Path & NewFileName & ".ipt",False)
          '  Call UpdateDrawing(Path, oldName, NewFileName)
			'iProperties.Value(refDoc.DisplayName, "Project", "Part Number") = NewFileName & ".ipt"
        End If
        FileChange = True
    End If
Next


If FileChange = True Then
	
	NewAssemblyName = InputBox("What is the new file name for the assembly?", "New Assembly File Name", iProperties.Value("Project", "Part Number" ) & ".iam")
	
	'If the name is unchanged
	If	NewAssemblyName =  ThisDoc.FileName(True) 'with extension
		NewAssemblyName = NewAssemblyName.substring(0,NewAssemblyName.length-4)
	
	'If there is a change in the name			
	Else
	'if the user also types in the extension then remove the extension.
	Dim oldName As String = ThisDoc.FileName(False) 'include extension
		If  NewAssemblyName.EndsWith(".iam") = True Then
        	NewAssemblyName = NewAssemblyName.substring(0,NewAssemblyName.length-4)
			ThisDoc.Document.SaveAs(Path & NewAssemblyName & ".iam", False)
			iProperties.Value("Project", "Part Number") = NewAssemblyName
			InventorVb.DocumentUpdate()
			'Dim oldName As String = ThisDoc.FileName(False) 'include extension
			'Call UpdateDrawing(Path, oldName, NewAssemblyName)
		Else		
   			If NewAssemblyName <> "" Then
        		'Dim oldName As String = ThisDoc.FileName(False) 'include extension
        		ThisDoc.Document.SaveAs(Path & NewAssemblyName & ".iam" , False)
				iProperties.Value("Project", "Part Number") = NewAssemblyName
				InventorVb.DocumentUpdate()
				'Call UpdateDrawing(Path, oldName, NewAssemblyName)
	 		End If
		End If
		Call UpdateDrawing(Path, oldName, NewAssemblyName)
	End If
	AssemblyName = NewAssemblyName
End If
		
iLogicVb.UpdateWhenDone = True
'Calls the RENAME BROWSER NODES rule to update the name of the files in the tree
iLogicVb.RunExternalRule("Rename Browser Nodes")

'Dim sFileName As String = Path & AssemblyName & ".idw"
'oDestinationDoc = ThisApplication.Documents.Open(sFileName,False)
'oDestinationDoc.PropertySets("Design Tracking Properties").Item("Part Number").Value = AssemblyName
	
End Sub

Private Sub UpdateDrawing (ByVal Path As String, ByVal oldName As String, ByVal newName As String)
    Dim oDestinationDoc As DrawingDocument
    Dim strFileExtension As String = oldName.substring(oldName.Length-4,4)
    'oldName = oldName.substring(0,oldName.Length-4)
    Dim sFileName As String = Path & oldName & ".idw"
   
    Try
        If System.IO.File.Exists(sFileName) Then
            oDestinationDoc = ThisApplication.Documents.Open(sFileName)
            oDestinationDoc.saveas(Path & newName & ".idw",False)
            Dim oDocDescriptor As DocumentDescriptor
            oDocDescriptor = oDestinationDoc.ReferencedDocumentDescriptors.Item(1)
   
            Dim oFileDescriptor As FileDescriptor
            oFileDescriptor = oDocDescriptor.ReferencedFileDescriptor
           
            oFileDescriptor.ReplaceReference(Path & newName & strFileExtension)
            oDestinationDoc.Update()
            oDestinationDoc.Close
        End If
		MessageBox.Show("No .idw Drawing File Found")
    Catch
        oDestinationDoc.Close
        MessageBox.Show(".idw Drawing File Name Changed to" & newName & ".idw")
    End Try
iLogicVb.UpdateWhenDone = True
iLogicVb.RunExternalRule("Rename Browser Nodes")
End Sub

 "Rename Browser Nodes.iLogicVb"

 

' set a reference to the assembly component definintion.
' This assumes an assembly document is open.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
'Iterate through all of the occurrences
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences
oOccurrence.Name = "" 'reset name to nothing, which pulls in the original name
Next

 

Many thanks in advance

reginald

 

 

4 REPLIES 4
Message 2 of 5
MegaJerk
in reply to: reginaldmb

Being that you have Inventor, you also have the Design Assistant that will allow you to copy and rename all of the children files that relate back to the main document that you’d like to copy (typically a Drawing or Assembly). This will let you do so in a controlled environment without any coding to get hung up on.

Better yet, if you have Vault, you can rename / re-organize things even easier! This article describes the variety of methods to rename your files without you having to get your hands dirty.

http://www.cadsetterout.com/inventor-tutorials/the-secrets-of-copying-assembly-files/


Does this help? 



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
Message 3 of 5
reginaldmb
in reply to: MegaJerk

HI MegaJerk

 

Thanks for your post.  Design Assistant is indeed a very handy tool.  Often it is just much faster to get the drafter to rename the item the moment it is placed to ensure that the drafter assign a part name that is unique say based on the project number and specific area.  We make use of a big library of created iLogic parts and just too often drafters place a part without renaming it.....in the end 10 projects end up with the different parts but with the same part name.  Same goes for assemblies......chaos

Message 4 of 5

Hi reginaldmb,

 

Question 1: How can I automatically run an external rule in all assemblies an inventor user opens (new or existing).

 

See this link:

http://beinginventive.typepad.com/being-inventive/2012/02/injecting-ilogic-code-and-ilogic-event-tri...

 

Question 2

 

I had a quick look, but it would take me a bit of time to work through your code. Unfortunatly I don't have the time to do that at the moment, but I might be able to get back to this later.

 

Have you considered just using the Copy tool with the Open in New Window option:

See this link:

http://forums.autodesk.com/autodesk/attachments/autodesk/78/365280/1/Copy%20IAM.png

and this link:

http://help.autodesk.com/view/INVNTOR/2014/ENU/?guid=GUID-5AAA6CB1-7BB2-4AF0-9A3D-AB729E5160C5

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

Message 5 of 5

Thanks Curtis. About question 2: We regularly use the copy tool and it works well for some applications. My actual problem is finding a way to force a user to rename a file with a "project-specific" name when placing either a .iam or .ipt file in a main assembly. the reason for this is to ensure that all files have unique names and allowing one in the end to check into vault.

Would be glad if you could look at it at some stage.

thanks
reginald

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

Post to forums  

Autodesk Design & Make Report