Convert Points from part to assembly

Convert Points from part to assembly

halganabi
Contributor Contributor
412 Views
7 Replies
Message 1 of 8

Convert Points from part to assembly

halganabi
Contributor
Contributor

I have assembly, that have part repeated many times in different locations, 
inside the part there is Workpoint called "TH" 
in the assembly, i need code to take all TH points and convert them to Workpoints inside the assembly,

plus : 
* if possible that all workpoint te be inside folder
* if possible to put all of these points inside a part together. 


0 Likes
Accepted solutions (1)
413 Views
7 Replies
Replies (7)
Message 2 of 8

WCrihfield
Mentor
Mentor

Hi @halganabi.  When you create WorkPoints in an assembly by code, even though there are several methods for creating WorkPoints in parts, only the AddFixed method will work on an assembly, leaving that point static (will not update or move with any other geometry).  So, if you moved any of those parts after creating the WorkPoints in the assembly, the new WorkPoints will no longer be accurate to the part locations.  They will remain in the previous location, where they were created.  It sounds like you want all new WorkPoints that get created within the assembly to be created in a browser tree folder, correct?  That may be possible.  But what do you mean by 'put all those points inside a part together'?  There is just one WorkPoint in each part named that way, right?  Please explain in more detail.

What do you plan on doing with these new WorkPoints once they exist in the assembly?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 8

halganabi
Contributor
Contributor

attached part and assembly, 
only as an Example of the idea to generate code for it, not the system that I am working on

in the assembly, there is a part called "PARTS" this part has a work point called "TH".
This part is repeated many times in the assembly in different positions. so points TH are scattered in many positions.

so simply the code I need is to look for all "TH" points and convert them to new Fixed Workpoints at the assembly.

Yes, it is ok that these points will not move later on, 
I will do this step after I finalize everything, if I will make changes later on it is ok that I run the code again and generate a new work points every time.

0 Likes
Message 4 of 8

xenocatalyst
Advocate
Advocate

Did you ever get this working? 

I could use this in my current project.

0 Likes
Message 5 of 8

halganabi
Contributor
Contributor

@xenocatalyst 
did not work for me yet,
but there should be a solution or work around way, 
we need clever one to discover it 😉

0 Likes
Message 6 of 8

WCrihfield
Mentor
Mentor
Accepted solution

Hi guys.  I will post an example iLogic rule here that you can review, modify as needed, and test with.  It is currently set-up to find 'all' custom (not Origin) WorkPoints in 'all' part type components, and try to create a fixed WorkPoint in the assembly for their proxy location.  I did leave a line of code in there ("If oOccWPt.Name = "TH" Then"), which is specific to @halganabi original request, but left it commented out for now, to make it a bit more universal for everyone to test with.  It also tries to assign a logical name to each new fixed work point it creates, based on parent component name, and original work point name.  I also included a couple extra lines of code (which I also left commented out for now) for setting the 'original' WorkPoint's 'Adaptive' status on, and possibly turning the new fixed assembly WorkPoint's Adaptive status on.  I do not personally use that where I work, so I am not super familiar with how it works, but it seems to allow constraints to that 'adaptive' status object to be 'moved' by changes to the assembly constraints that are associated with it in the assembly.  Just something else that you may be able to look into for testing purposes.

Sub Main
	Dim oInvApp As Inventor.Application = ThisApplication
	Dim oADoc As AssemblyDocument = TryCast(ThisDoc.Document, Inventor.AssemblyDocument)
	If oADoc Is Nothing Then Return
	Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
	Dim oAsmWPts As WorkPoints = oADef.WorkPoints
	Dim oOccs As ComponentOccurrences = oADef.Occurrences
	For Each oOcc As ComponentOccurrence In oOccs
		If oOcc.Suppressed Then Continue For
		If (Not TypeOf oOcc.Definition Is PartComponentDefinition) Then Continue For
		Dim oOccPDef As PartComponentDefinition = oOcc.Definition
		Dim oOccWPts As WorkPoints = oOccPDef.WorkPoints
		For Each oOccWPt As WorkPoint In oOccWPts
			If oOccWPt.IsCoordinateSystemElement OrElse
				oOccWPt.Construction Then
				Continue For
			End If
			'If oOccWPt.Name = "TH" Then
			'oOccWPt.Adaptive = True 'something to look into
			Dim oOccWPtProxy As WorkPointProxy = Nothing
			oOcc.CreateGeometryProxy(oOccWPt, oOccWPtProxy)
			Dim oAsmWPt As WorkPoint = oAsmWPts.AddFixed(oOccWPtProxy.Point, False)
			Try : oAsmWPt.Name = oOcc.Name & " - " & oOccWPt.Name : Catch : End Try
			'oAsmWPt.Adaptive = True 'something to look into
		Next oOccWPt
	Next oOcc
	oADoc.Update2(True)
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 8

xenocatalyst
Advocate
Advocate

That works Fantastically, thankyou.

 

 

0 Likes
Message 8 of 8

WCrihfield
Mentor
Mentor

Now that I'm looking at it again, and thinking about the situation(s) where you may want to run this same rule again, to update things, that original code could use s few tweaks to help with encountering those already existing fixed WorkPoints, and updating them.  I suppose you could simply delete them if found, then create them again, but there is actually a way to update the existing ones, without doing that.  Below is an updated version of that code, which will now check for that existing fixed WorkPoint, by the custom and unique name we are assigning it in the code, and if found, it will update its 'definition' using that same proxy point location.  If it is not found, then it will proceed to create it, as usual.  The process of updating existing work features varies a lot between part and assembly, and by how the feature was originally created.  In an assembly, since we can only create 'fixed' work features, their 'definition type' (AssemblyWorkPointDef) is pretty much always the same...for that type of work feature anyways.  See if this works better for you in 'repeat/update' type situations, such as after you moved some of those parts around in the assembly.

 

One thing this still does not do though...if you delete some of those part components out of the assembly, I am not sure that those fixed WorkPoints will also be deleted with them, since there is no 'real' association between the WorkPoint and the component.  So, keep an eye out for that situation.  If we were creating these in a part, and using 'regular' methods for defining them that were based on 'real' geometry, then they would be deleted (or broken) when the geometry they are associated with was deleted.

Sub Main
	Dim oInvApp As Inventor.Application = ThisApplication
	Dim oADoc As AssemblyDocument = TryCast(ThisDoc.Document, Inventor.AssemblyDocument)
	If oADoc Is Nothing Then Return
	Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
	Dim oAsmWPts As WorkPoints = oADef.WorkPoints
	Dim oOccs As ComponentOccurrences = oADef.Occurrences
	For Each oOcc As ComponentOccurrence In oOccs
		If oOcc.Suppressed Then Continue For
		If (Not TypeOf oOcc.Definition Is PartComponentDefinition) Then Continue For
		Dim oOccPDef As PartComponentDefinition = oOcc.Definition
		Dim oOccWPts As WorkPoints = oOccPDef.WorkPoints
		For Each oOccWPt As WorkPoint In oOccWPts
			If oOccWPt.IsCoordinateSystemElement OrElse
				oOccWPt.Construction Then
				Continue For
			End If
			Dim oOccWPtProxy As WorkPointProxy = Nothing
			oOcc.CreateGeometryProxy(oOccWPt, oOccWPtProxy)
			Dim oAsmWPt_Name As String = oOcc.Name & " - " & oOccWPt.Name
			Dim oAsmWPt As WorkPoint = Nothing
			Try
				oAsmWPt = oAsmWPts.Item(oAsmWPt_Name)
				Dim oAsmWPtDef As AssemblyWorkPointDef = oAsmWPt.Definition
				oAsmWPtDef.Point = oOccWPtProxy.Point
			Catch
				oAsmWPt = oAsmWPts.AddFixed(oOccWPtProxy.Point, False)
			End Try
			If oAsmWPt.Name <> oAsmWPt_Name Then
				Try : oAsmWPt.Name = oAsmWPt_Name : Catch : End Try
			End If
		Next oOccWPt
	Next oOcc
	oADoc.Update2(True)
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes