Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get appearance and put into custom property for IDW

6 REPLIES 6
Reply
Message 1 of 7
LSA-skan
634 Views, 6 Replies

Get appearance and put into custom property for IDW

Hi

 

Im trying to adjust a rule to add the Appearance value, to a custom property so i can add it to my IDW title block.

 

I know I can get the value from parts by using iProperties.PartColor, but that only works when the active document is a part. 

 

I want to have the rule go through all sub parts and assys, and put the appearance into a custom property called Surface.

 

If I break it up it contains 2 challenges.:

When standing on topassy

 

1. For sub parts, the rule must retrieve the appearance value of a sub part, and put it into the parts custom property called surface.

2. For sub assys, the rule must retrieve the appearance value from the first part (anyone will do), in a sub assy. as it is the parts, that are colored in an assy, and not the assy itself. And also put that in the assys custom property called surface

 

hope my question makes sence, and that it can be solved failry easy 🙂

 

here is the code i want it embedded into.:

 

Dim openDoc As Document
Dim docFile As Document
Dim assemblyDoc As AssemblyDocument
Dim assemblyDef As AssemblyComponentDefinition
Dim partQty As ComponentOccurrencesEnumerator
Dim FNamePos As Long
Dim docFName As String
Dim Ordre As String
Dim Surface As String

ThisApplication.StatusBarText = "Jeg arbejder... rolig nu.!"

openDoc = ThisDoc.Document        
Ordre = iProperties.Value("Project", "Project")
Ordre = InputBox("Er " & Ordre & " det rigtige ordre nr? Ellers skriv det rigtige", "Ordre nummer", Ordre)
iProperties.Value("Project", "Project") = Ordre
'Surface = InputBox("bestem farve","Rød",Surface)
If openDoc.DocumentType = kAssemblyDocumentObject Then  
    For Each docFile In openDoc.AllReferencedDocuments
    FNamePos = InStrRev(docFile.FullFileName, "\", -1)        
        docFName = Mid(docFile.FullFileName, FNamePos + 1, Len(docFile.FullFileName) - FNamePos)
        If docFile.IsModifiable = True Then
        assemblyDoc = openDoc        
        assemblyDef = assemblyDoc.ComponentDefinition
        partQty = assemblyDef.Occurrences.AllReferencedOccurrences(docFile)
                Try
                    If partQty.Count <>  iProperties.Value(docFName, "Custom", "PCS") Then                
                        iProperties.Value(docFName, "Custom", "PCS") = partQty.Count
                    End If                      
                    Catch
                        iProperties.Value(docFName, "Custom", "PCS") = partQty.Count
                End Try
                Try
                    If Ordre <>  iProperties.Value(docFName, "Project", "Project") Then                
                        iProperties.Value(docFName, "Project", "Project") = Ordre
                    End If                      
                    Catch
                        iProperties.Value(docFName, "Project", "Project") = Ordre
                End Try
		'This is the new code
		'sub part
                If docFile.DocumentType = kPartDocumentObject Then
		    Surface = iProperties.PartColor
		    MessageBox.Show(Surface, "Title")
		Else
                'sub assy
		End If
		Try
		If Surface <>  iProperties.Value(docFName, "Custom", "Surface") Then                
                        iProperties.Value(docFName, "Custom", "Surface") = partQty.Count
                    End If                      
                    Catch
                        iProperties.Value(docFName, "Custom", "Surface") = partQty.Count
                End Try
        End If
    Next
    ThisApplication.StatusBarText = "Ready"
Else
MessageBox.Show("Du kan KUN køre denne regel i en Assembly", "Forkert Filtype",MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
End If 

 

 

Using

Inventor Premium 2013

 

/LSA-Skan

 

 

 

 

6 REPLIES 6
Message 2 of 7
wood.isbell
in reply to: LSA-skan

1. Rather than iProperties.PartColor use docFile.ActiveAppearance.DisplayName in the newer versions of Inventor.

 

2. You should be able to accomplish this a number of ways, but it seems strange that you do not care which sub-component would populate the custom iProperty of the parent assembly. The easy way would be to make two loops. One for parts and one for sub-assemblies which would look for the next part in the list and populate your value from that. There may be a better way of referencing the next object in the loop without continuing it, but I am not sure.

Message 3 of 7
LSA-skan
in reply to: wood.isbell

Hi Wisbell

 

I understand why you think it´s strange 🙂 actually there might be a twist in this, I may have to consider... We have Welding assys and mounting assys. (we do not use the Weldment function in inventor though) so a sub assy may be both, 90% of the time it´s a weldment, and in that case alle the parts will have the same color, and when this is so, it doesn't matter what part's Appearance i pick... however the top assy is almost always a mounting assy. and in this case it won't work to pick a random part or assy as they can easily have different colors. Therefore im thinking i might have to make the rule NOT put anything in the Surface property when more appearances are present in any one assy.!

 

I will try your suggestion for 1.

 

regarding 2. i think your right, i was thinking a loop for checking appearance on parts/sub assys, and then if they are the same, that value is put in the surface property, if not, nothing is done. however i might need some help creating these loops, as i am not very skilled in coding yet... 🙂

 

/LSA-Skan

Message 4 of 7
wood.isbell
in reply to: LSA-skan

Below is a little example (untested) which should get your loops going. You will have to insert your code in the correct subs, but this should handle your loops. The only thing I don't like is that you are looping through parts in sub-assemblies multiple times. You could get around this by counting the parts in the sub-assemblies and skipping that many instances of your top loop, but I will leave that up to you. It shouldn't make much difference, I just don't like it.

 

Private Sub Main()
	'current document
	Dim oDoc As Document = ThisApplication.ActiveDocument
	'top loop
	For Each doc In oDoc.AllReferencedDocuments
		'do stuff for each document type
		Select Case doc.DocumentType
			Case kAssemblyDocumentObject
				'call sub
				AssemblyStuff(doc)
			Case kPartDocumentObject
				'call sub
				PartStuff(doc)
		End Select
	Next
End Sub
'assembly sub
Sub AssemblyStuff(oSubDoc)
	Dim sColor As String
	For Each subdoc In oSubDoc.AllReferencedDocuments
		'catch and skip sub-assemblies in our sub-assembly
		'these should be handled by the main loop
		If subdoc.DocumentType = kAssemblyDocumentObject Then Continue For
		'sColor is set yet
		If sColor <> Nothing Then
			'sColor is not equal to this part's color
			'our parts in the sub-assembly do not have the same color
			'so skip this Sub-Assembly
			If sColor <> subdoc.ActiveAppearance.DisplayName Then Exit Sub
		'sColor isn't set
		Else
			'set sColor to current part's color
			sColor = subdoc.ActiveAppearance.DisplayName
		End If
	Next
	'after this loop finishes, you can set your iProperty from sColor
End Sub
'part sub
Sub PartStuff(oSubDoc)
	'set your iProperty from oSubDoc.ActiveAppearance.DisplayName
End Sub

Edit: missed a spot. fixed. 

Message 5 of 7
LSA-skan
in reply to: wood.isbell

Thanks alot for your time helping me..!!

 

About multiple looping, then I have actually thought about separating this code to it´s own stand alone function, as it´s not always we need this function, but the other i linked before is used always...

 

The code is complaining about not being able to find the public member Active Appearance in the type PartDocument. You mentioned it should work in newer versions of Inventor.. how new? im using 2013..

 

/LSA-Skan

 

 

 

 

Message 6 of 7
wood.isbell
in reply to: LSA-skan

It looks like Assets were introduced in 2014. A resource you should look for is the programming help. In 2014, you can access this from the help (?) dropdown > Community Resources > Programming Help. This is where I found the Asset method of finding part color. I did a quick search, but cannot find the equivalent to Assets in previous versions. It may be referenced as Color, but I am not sure where. See if you can find it in that help file.

 

The help file may also be located in C:\Program Files\Autodesk\Inventor 2013\Local Help\ named something like admapi...chm

Message 7 of 7
LSA-skan
in reply to: wood.isbell

Ahh.. ok.. we are actually thinking of upgrading to 2014 within the next months, so i guess i´ll have to wait till then.. 🙂 i might get back to this thread when that happends...!

 

/LSA-Skan

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

Post to forums  

Autodesk Design & Make Report