check parameter values of parts in an assembly without pass through or linking

check parameter values of parts in an assembly without pass through or linking

Koekepeerke
Advocate Advocate
465 Views
3 Replies
Message 1 of 4

check parameter values of parts in an assembly without pass through or linking

Koekepeerke
Advocate
Advocate

Hello everyone,

 

To get coordinate information of certain components in an assembly i want to search for specific parameter values in all parts. So when the value matches i can try to retrieve de coordinates of the centerpoint of the specific part. 

I can't link or pass the parameters through because there are going to be too many parts, we dont want to link all the parameters for every project again and also the naming would probably be a problem.

Retrieving the coordinates would be the next step, first i would like to see if it's possible check for the parameters in all parts. I found this piece of code but ofcourse this doesn't work if the parameter isn't in the assembly itself.

 

Dim oParamName As String = ""
Dim LookForName As String = "parameter name"

For Each oParam As Parameter In oDef.Parameters
	oParamName = oParam.Name
	If oParamName.Contains(LookForName) Then 
		MessageBox.Show(oParamName, "Title")
	End If
Next

Does anybody know if something like this is possible and if yes how?

 

Thanks! 

0 Likes
466 Views
3 Replies
Replies (3)
Message 2 of 4

dalton98
Collaborator
Collaborator

Something like this might be what you are looking for. I'm not sure what your parameter value would look like or if your refering to the origin point as the center or say the center of gravity value.

Dim LookForName As String = "parameter name"

Dim oAss As AssemblyDocument
oAss = ThisApplication.ActiveDocument

Dim oRefDoc As PartDocument
For Each oDoc In oAss.AllReferencedDocuments
	Dim param As Inventor.Parameter
	Try
		param = oRefDoc.ComponentDefinition.Parameters.Item(LookForName)
	Catch
		MessageBox.Show("doesnt exist")
		Dim oPoint As Point
		'the origin is a work point
		oPoint = oRefDoc.ComponentDefinition.WorkPoints.Item(1).Point
		If oPoint.X And oPoint.Y And oPoint.Z = 0
			oRefDoc.ComponentDefinition.Parameters.UserParameters.AddByExpression(LookForName, "0", UnitsTypeEnum.kTextUnits)
		Else
			'idk
		End If
	End Try
Next
Message 3 of 4

Koekepeerke
Advocate
Advocate

Hello Dalton,

 

First of all thanks for your quick reply! but i dont think this is quite what i'm looking for.

I'm trying to filter components on a certain hole stitch distance (wich is a parameter). so for instance if i have grid full of colomns and there are few colomns with this specific hole stitch feature i want the rule to give back the centerpoint/origin coordinates of these colomns without having to search for these particular colomns myself. another next step would be to then automatically position something on to these specific colomns. 

Not sure if i made my problem any clearer now. 

0 Likes
Message 4 of 4

dalton98
Collaborator
Collaborator

Ok that makes more sense. I couldn't find how to get the origin point so I used the the component range box and to get close. I went ahead and wrote it so that it will place the desired component at the 'origin' of the component. 

Dim oAss As AssemblyDocument
oAss = ThisApplication.ActiveDocument

Dim oOcc As ComponentOccurrence
For Each oOcc In oAss.ComponentDefinition.Occurrences
	Try
	'if oParam exists it will continue the try
	oParam = Parameter(oOcc.Name, "parameter name")
	Dim xpos As Double = (oOcc.RangeBox.MinPoint.X + oOcc.RangeBox.MaxPoint.X) / 4 
	Dim ypos As Double = (oOcc.RangeBox.MinPoint.Y + oOcc.RangeBox.MaxPoint.Y) / 4 
	Dim zpos As Double = (oOcc.RangeBox.MinPoint.Z + oOcc.RangeBox.MaxPoint.Z) / 4
	
	'create point
	Dim oPoint1 = ThisAssembly.Geometry.Point(xpos, ypos, zpos)
	'place component at point
	Dim componentA = Components.Add("", "part.ipt", oPoint1)
	Catch
	End Try
Next

 Also, if you would only like a visual of the columns with the correct parameter you could add this to the code to select them.

oAss.SelectSet.Select(oOcc)