ProjectToSurface access to the Created Curve

ProjectToSurface access to the Created Curve

florian_wenzel
Advocate Advocate
363 Views
3 Replies
Message 1 of 4

ProjectToSurface access to the Created Curve

florian_wenzel
Advocate
Advocate

Hi,

 

Inventor 2022

API VB.NET VisualStudio

 

i try to get access to the Created Curve with Method ProjectToSurface, but without success.

 

How to get the Curve?

i Dont want to Pick up this Curve with GUI.

 

This is my Code:

 

 

 

Imports System.Runtime.InteropServices
Imports Inventor
Imports Microsoft.Win32
Imports System.Collections.Generic
Imports System.Linq
Imports System.IO

Module CommandFunctionButton_08


    Public Sub CommandFunctionfweButton_08()

        Dim oPartDoc As PartDocument = g_inventorApplication.ActiveDocument
        Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
        Dim oTO As TransientObjects = g_inventorApplication.TransientObjects
        Dim oTG As TransientGeometry = g_inventorApplication.TransientGeometry


        'Pick the Surface
        Dim oSurface_01 As Face = g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick a Face")
        'Pick the Origin Curve
        Dim oGuideCurve As SketchEntity3D = g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kSketch3DCurveFilter, "Pick a Curve")

        'Create Face Coll
        Dim oFaceColl_forSurface As ObjectCollection
        oFaceColl_forSurface = oTO.CreateObjectCollection
        oFaceColl_forSurface.Add(oSurface_01)

        'Create Curve Coll
        Dim oCurveColl_forProjecting As ObjectCollection
        oCurveColl_forProjecting = oTO.CreateObjectCollection
        oCurveColl_forProjecting.Add(oGuideCurve)


        'ProjectToSurfaceCurves
        Dim oSketch3D_SurfaceCurve As Sketch3D = oCompDef.Sketches3D.Add
        oSketch3D_SurfaceCurve.ProjectToSurfaceCurves.Add(oFaceColl_forSurface, oCurveColl_forProjecting, ProjectCurveToSurfaceTypeEnum.kProjectToClosestPointType)

        'Create new Sketch 3D
        Dim oSketch3D_Curve3D As Sketch3D = oCompDef.Sketches3D.Add

        'Try to get Access to the Created Curve with ProjectToSurfaceCurves
        Dim oCurve3D As SketchEntity3D
        oCurve3D = oSketch3D_SurfaceCurve.Include(oSketch3D_SurfaceCurve.SketchEntities3D.Item(1))


    End Sub

End Module

 

 

 

Second Code also not working:

 

 Dim oCurveColl_forCurve As ObjectCollection
        oCurveColl_forCurve = oTO.CreateObjectCollection
        oCurveColl_forCurve.Add(oSketch3D_SurfaceCurve.ProjectToSurfaceCurves.Curves(1))

        Dim oCurve3D As SketchEntity3D
        oCurve3D = oCurveColl_forCurve.Item(1)

 

 

Other try:

florian_wenzel_0-1663062362938.png

 

oCurve3D.Curves(1) was Nothing

 

What is this for Curve type?

 

Thanks for any Suggestion

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

WCrihfield
Mentor
Mentor

Hi @florian_wenzel.  I see two places in the posted code that could be changed to get the ProjectToSurfaceCurve object...if that is what you were trying to obtain.  If that is not the 'Curve' you were trying to obtain, then I believe you would need to obtain 3 entities instead of just 1, because that is the number of SketchEntity3D objects created by projecting the geometry to the surface.  You could have declared a ProjectToSurfaceCurve Type variable just before using the first Add method which creates one, and used the Add line of code to set that variable's Value.  Also, in one of your lines of code which are attempting to retrieve a curve from the ProjectToSurfaceCurve object after the fact, you have "ProjectToSurfaceCurves.Curves(1)" at the end of the line, that would be accessing the input geometry which was used for creating it, not the resulting geometry.  I copied your code to an iLogic rule editor screen, then edited it slightly.  I had to declare and set a value for your 'g_inventorApplication' variable, because of the iLogic environment though.  I am not 100% sure what you wanted to do with the curve(s) once obtained, but I believe I have the first of 3 as the value of a variable at the end of this code.

Public Sub Main 'CommandFunctionfweButton_08()
	Dim g_inventorApplication As Inventor.Application = ThisApplication
	Dim oPartDoc As PartDocument = g_inventorApplication.ActiveDocument
	Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
	Dim oTO As TransientObjects = g_inventorApplication.TransientObjects
	Dim oTG As TransientGeometry = g_inventorApplication.TransientGeometry
	'Pick the Surface
	Dim oSurface_01 As Face = g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick a Face")
	'Pick the Origin Curve
	Dim oGuideCurve As SketchEntity3D = g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kSketch3DCurveFilter, "Pick a Curve")
	'Create Face Coll
	Dim oFaceColl_forSurface As ObjectCollection
	oFaceColl_forSurface = oTO.CreateObjectCollection
	oFaceColl_forSurface.Add(oSurface_01)
	'Create Curve Coll
	Dim oCurveColl_forProjecting As ObjectCollection
	oCurveColl_forProjecting = oTO.CreateObjectCollection
	oCurveColl_forProjecting.Add(oGuideCurve)
	'ProjectToSurfaceCurves
	Dim oPTSC As ProjectToSurfaceCurve = Nothing
	Dim oSketch3D_SurfaceCurve As Sketch3D = oCompDef.Sketches3D.Add
	oPTSC = oSketch3D_SurfaceCurve.ProjectToSurfaceCurves.Add(oFaceColl_forSurface, oCurveColl_forProjecting, ProjectCurveToSurfaceTypeEnum.kProjectToClosestPointType)
	MsgBox("oPTSC.SketchEntities.Count = " & oPTSC.SketchEntities.Count,,"")
	Dim oCurve3D As SketchEntity3D = oPTSC.SketchEntities.Item(1)
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 3 of 4

florian_wenzel
Advocate
Advocate

Hi WCrihfield

 

the Problem is a little bit complex.

I will use the Curve to Create Sweap, so corectly i use it to CreatePath.

 

It not working properly.

It Create a Curve, but you cant see it. Matematical Curve or something like that.

 

This is my Code:

 

Imports System.Runtime.InteropServices
Imports Inventor
Imports Microsoft.Win32
Imports System.Collections.Generic
Imports System.Linq
Imports System.IO

Module CommandFunctionButton_08


    Public Sub CommandFunctionfweButton_08()

        Dim oPartDoc As PartDocument = g_inventorApplication.ActiveDocument
        Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
        Dim oTO As TransientObjects = g_inventorApplication.TransientObjects
        Dim oTG As TransientGeometry = g_inventorApplication.TransientGeometry


        'Pick the Surface
        Dim oSurface_01 As Face = g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick a Face")
        'Pick the Origin Curve
        Dim oGuideCurve As SketchEntity3D = g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kSketch3DCurveFilter, "Pick a Curve")

        'Create Face Coll
        Dim oFaceColl_forSurface As ObjectCollection
        oFaceColl_forSurface = oTO.CreateObjectCollection
        oFaceColl_forSurface.Add(oSurface_01)

        'Create Curve Coll
        Dim oCurveColl_forProjecting As ObjectCollection
        oCurveColl_forProjecting = oTO.CreateObjectCollection
        oCurveColl_forProjecting.Add(oGuideCurve)


        'ProjectToSurfaceCurves
        Dim oSketch3D_SurfaceCurve As Sketch3D = oCompDef.Sketches3D.Add

        Dim oProjectingCurves As ProjectToSurfaceCurve
        oProjectingCurves = oSketch3D_SurfaceCurve.ProjectToSurfaceCurves.Add(oFaceColl_forSurface, oCurveColl_forProjecting, ProjectCurveToSurfaceTypeEnum.kProjectToClosestPointType)

        'Create new Sketch 3D
        Dim oSketch3D_Curve3D As Sketch3D = oCompDef.Sketches3D.Add

        Dim oCurve3D As SketchEntity3D
        For i = 1 To oProjectingCurves.SketchEntities.Count
            oCurve3D = oProjectingCurves.SketchEntities.Item(i)
        Next



    End Sub

End Module

 

 

 

 

I  put the Part After Feature. Last Sketch 3D is Empty.

 

The Problme is also, that i want to convert this Curve to SketchSpline3D.

Because i want StartSketchPoint and EndPoint from it.

So i can Create a WorkPlane Normal to Curve.

 

So ist a little bit Complicatetd.

 

 

 

Thanks for Any Suggestion

 

0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor
Accepted solution

Hi @florian_wenzel.  I looked at the object Type of each of the 3 sketch entities that were projected, and found that the first two are SketchPoint3D objects, and the third is already a SketchSpline3D object.  So, where you are using a loop to 'include' the sketch entities, you could be checking their Type (ObjectTypeEnum) or using TypeOf operator to find the SketchSpline3D object, then just use that as needed.  I am not sure why a third Sketch3D would be needed.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)