Get WorkPlane used within a sketch as projected geometry

Get WorkPlane used within a sketch as projected geometry

gerald_engineers
Participant Participant
80 Views
1 Reply
Message 1 of 2

Get WorkPlane used within a sketch as projected geometry

gerald_engineers
Participant
Participant

The situation:

  • A 2D-sketch is made.
  • As reference a WorkPlane is projected into the sketch
  • A DimensionConstraints.AddOffset is made between the sketch geometry and the projected Workplane geometry.

The purpose:

  • The feature shall be extracted from the part. The extracted data shall even containthe constraints that were made to the predefined Workplanes.
  • In other parts the Feature shall be inserted with the same dimensions related to predefined Workplanes of those other parts.

 

The part problem I try so solve now:

Get the DimensionConstraint that uses the projected WorkPlane and know which WorkPlane it is.

 

This is either hard to get or I am on the wrong track. 

 

What I tried so far:

Dim feature As PartFeature = ThisDoc.Document.ComponentDefinition.Features.Item(1)
Dim featureProfile As Profile = feature.Definition.Profile
Dim featureSketch As Sketch = featureProfile.Parent

' APPROACH 1: Coming from the Sketch-side
For Each sketchEntity In featureSketch.SketchEntities
	Dim someConstraint As Object
	For Each someConstraint In SketchEntity.Constraints
		Try
		Logger.Info("Constraint:   " & someConstraint.Type & ", " &  someConstraint.Parameter.Expression)
		' Is there a way to go further here to "reach" the WorkPlane?
		Catch
		End Try
	Next
Next

' APPROACH 2: Coming from the WorkPlane-side
Dim referenceWorkPlanes = New WorkPlane() {workPlanes.Item("MyWorkplane01"), workPlanes.Item("MyWorkplane02")}
Dim workPlane As WorkPlane
For Each workPlane In referenceWorkPlanes
	Logger.Info("Name of WorkPlane: " & workPlane.Name)
	Dim dependent As Object
	For Each dependent In workPlane.Dependents
		Logger.Info("Type of dependent:  " & dependent.Type)
		
		' Continue only for SketchLine objects
		If (dependent.Type <> kSketchLineObject) Then Continue For

		Logger.Info("Name of sketch:       " & dependent.Parent.Name)

		Dim someConstraint As Object
		For Each someConstraint In dependent.Constraints
			Dim anchorPoint As Object
			' PROBLEM: Getting the anchor points is not helpful. They are just TransientGeometry and
			'				'          do not have a connection to the sketch(!?)
			'				For Each anchorPoint In offsetDimConstraint.AnchorPoints
			'					Logger.Info("( " & anchorPoint.X & " / " & anchorPoint.Y & " )")
			'				Next
			
			' Is there a way to go further here to "reach" the sketchEntity that is used by this constraint?				
		Next
	Next
Next

 

My next idea is to tackle the problem "from both sides":

  1. Coming from the WorkPlane-side (= approach 2 in the example above) I collect all dependants (which are projected lines) and store them in an array (multi-dimensional: one sub-array for every WorkPlane).
  2. Coming from the Sketch-side (= approach 1 in the example above) I see whether any SketchEntity is in one of the arrays from step 1.
  3. If there is a match I can get the Constraint from the SketchEntity and get the "connection" this way.

Other approaches might be working with ReferenceKeys or Attributes.

 

But all this feels not Inventor-native.

There must be a better way to solve this?

0 Likes
81 Views
1 Reply
Reply (1)
Message 2 of 2

gerald_engineers
Participant
Participant

I think I found a suitable way to reach the WorkPlane via "APPROACH 1". I missed the properties `Reference`, `ReferenceComponent` and `ReferencedEntity` of the SketchLine Object

This solves my problem. Or are there better solutions anyway?

0 Likes