In-Place Edit fails

In-Place Edit fails

gilsdorf_e
Collaborator Collaborator
785 Views
3 Replies
Message 1 of 4

In-Place Edit fails

gilsdorf_e
Collaborator
Collaborator

Hi, I'm struggeling to run a code that works well for parts, but fails when running on an in-place edited part.

 

Basically it fails when trying to add a sketch with

 

 

PartComponentDefinition.Sketches.Add(selectedPlanarFace, false)

 

 

The workflow would be that the user starts in-place edit of a part component. Then the Inventor Addin is started and asks the user to pick a face. Based on that selection, it creates a planar sketch on this face.

When run directly for the part component everything works well.
When run in-place, I'm getting the ActiveEditDocument. Casting as PartDocument and reading existing sketches from

PartComponentDefinition works well in Debugging. As soon as I try adding a new PlanarSketch with the selected planar face, it will crash with "Wrong parameter".

I suspect that the selected face is somehow in occurence context, so it cannot be used to create a new sketch.

Any ideas, someone?

0 Likes
Accepted solutions (1)
786 Views
3 Replies
Replies (3)
Message 2 of 4

Michael.Navara
Advisor
Advisor
Accepted solution

When you pick the face in assembly context, it is FaceProxy object (not Face object). In this case you can use 

Dim oFace as Face = selectedPlanarFace.NativeObject

 

0 Likes
Message 3 of 4

gilsdorf_e
Collaborator
Collaborator

Yesss. I was just going to post that is was a proxy issue. Sometimes it helps writing down you issue. Thank you anyways.

0 Likes
Message 4 of 4

cmcgoughHSS
Explorer
Explorer

I am having a similar issue, but I have already resolved the face proxy to a face object.

I am trying to create a sketch centered on a face, so I have identified the center point and can successfully place a work point at that location, but cannot seem to use it as the origin of the sketch.

 

	Dim oPartDoc As Inventor.PartDocument
	
	If ThisApplication.ActiveDocumentType = kpartDocumentObject Then
			oPartDoc = ThisApplication.ActiveDocument
		Else If ThisApplication.ActiveDocumentType = kAssemblyDocumentObject And ThisApplication.ActiveEditDocument.DocumentType = kpartDocumentObject Then
   			oPartDoc = ThisApplication.ActiveEditDocument
		Else
			i = MessageBox.Show("No part file selected for edit", "No Part for Edit", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
			Exit Sub
  	End If

	Dim oCompDef As Inventor.PartComponentDefinition = oPartDoc.ComponentDefinition

    Dim oTransGeom As Inventor.TransientGeometry = ThisApplication.TransientGeometry
	Dim oPickFace As Inventor.FaceProxy = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select Surface to Place Text")
	Dim oSketchAxis As Inventor.Edge
	
	Dim oSketchFace As Inventor.Face = oPickFace.NativeObject
	
	Dim edge1 As Inventor.Edge = oSketchFace.Edges.Item(1)
	Dim edge2 As Inventor.Edge = oSketchFace.Edges.Item(2)
	Dim curve1Eval As CurveEvaluator = edge1.Evaluator
	Dim curve2Eval As CurveEvaluator = edge2.Evaluator
	Dim maxP As Double
	Dim minP As Double
	Dim curveLength1 As Double 
	Dim curveLength2 As Double
	
	Call curve1Eval.GetParamExtents(minP,maxP)
	Call curve1Eval.GetLengthAtParam(minP, maxP, curveLength1)
	Call curve2Eval.GetParamExtents(minP, maxP)
	Call curve2Eval.GetLengthAtParam(minP, maxP, curveLength2)
	
	If curveLength1 > curveLength2 Then
		oSketchAxis = edge1
	Else
		oSketchAxis = edge2
	End If
	
	Dim oEdgeLoop As Inventor.EdgeLoop = oSketchFace.EdgeLoops.Item(1)
	Dim oMinPt As Inventor.Point = oEdgeLoop.RangeBox.MinPoint 
	Dim oMaxPt As Inventor.Point = oEdgeLoop.RangeBox.MaxPoint
	Dim oCtPoint As Inventor.Point = oTransGeom.CreatePoint((oMaxPt.X + oMinPt.X) / 2#, (oMaxPt.Y + oMinPt.Y) / 2#, (oMaxPt.Z + oMinPt.Z) / 2#)
	
	'Fails here at sketch creation
	Dim oSketch As Inventor.PlanarSketch = oCompDef.Sketches.AddWithOrientation(oSketchFace, oSketchAxis, True, True, oCtPoint)

 

0 Likes