Create a Point from Vertex or Object in Assembly Enviroment

Create a Point from Vertex or Object in Assembly Enviroment

florian_wenzel
Advocate Advocate
1,199 Views
11 Replies
Message 1 of 12

Create a Point from Vertex or Object in Assembly Enviroment

florian_wenzel
Advocate
Advocate

Inventor 2022

API Visual Studio VB.NET

 

Hi,

i try to insert a Part in Assembly.

I want to Put the Part in a Position, which is defined with a SelectingPoint.

 

The Goal is to Set the Part in a StartPoint from a Projecting Curve.

Actualy, i want to Create a New Part, so that the Origin Point will be in Position of Start Point from Projecting Curve.

florianwenzelEJNZZ_1-1654083165290.png

 

 

florianwenzelEJNZZ_0-1654083148600.png

 

I got Error, when i select the Point.

This is the Code:

 

Imports System.Runtime.InteropServices
Imports Inventor
Imports Microsoft.Win32

Module CommandFunctionButton_01
    Public Sub CommandFunctionfweButton_01()

        Dim oAsmDoc As AssemblyDocument = g_inventorApplication.ActiveDocument
        Dim oAsmCompDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition


        Dim oTO As TransientObjects = g_inventorApplication.TransientObjects
        Dim oTG As TransientGeometry = g_inventorApplication.TransientGeometry


        Dim oPointOriginSet As Vertex = g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kAllPointEntities, "Pick a Point")

        Dim oPointOrigin As Point
        oPointOrigin = oPointOriginSet.Point




        Dim oXAxis As Vector = oTG.CreateVector(1, 0, 0)
        Dim oYAxis As Vector = oTG.CreateVector(0, 1, 0)
        Dim oZAxis As Vector = oTG.CreateVector(0, 0, 1)


        Dim oMatrix As Matrix = oTG.CreateMatrix
        Call oMatrix.GetCoordinateSystem(oPointOrigin, oXAxis, oYAxis, oZAxis)

        Dim oOcc As ComponentOccurrence = oAsmCompDef.Occurrences.Add("C:\InventorAPI\001\CAD\3D\Part_02.ipt", oMatrix)


    End Sub
End Module

 

florianwenzelEJNZZ_2-1654083356823.png

 

Where is the Problem?

I was Trying o create the Point with, Object or Vertex, but always get a Error.

I dont want to write the Coordinate, i want to Select the Point.

 

Actualy, i want to Create a New Part, so that the Origin Point will be in Position of Start Point from Projecting Curve.

 

Thanks for any Suggestion

0 Likes
Accepted solutions (2)
1,200 Views
11 Replies
Replies (11)
Message 2 of 12

WCrihfield
Mentor
Mentor

Hi @florian_wenzel.  When you select a Vertex within the context of an assembly, the selected object will be a VertexProxy, instead of a regular Vertex.  Then later, after you create a new Matrix, it looks like you may be using the wrong method for specifying its coordinate system.  You are using the Get method, when it seems you should be using the Set method.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 12

florian_wenzel
Advocate
Advocate

Hi,

Still Error

florianwenzelEJNZZ_0-1654087985371.png

 

0 Likes
Message 4 of 12

WCrihfield
Mentor
Mentor

Well, I can't read the error message, because it is in a language I am not fluent in, but I can tell it is having trouble with a Type mismatch.  When I use the Pick method, I usually do not declare the variable's Type ahead of time, then on the next line, check if anything was picked, then check the Type of the picked object, and if the Type is not what I am expecting, I do not progress forward.  So, you could create a generic Object Type variable to store the picked object to at first, then check what you picked on the next line, before continuing.  Is it possible you are picking a WorkPoint instead of a Vertex/VertexProxy?

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 12

florian_wenzel
Advocate
Advocate

actually the idea is, to use or Select the Start points from a Curve in a Assembly Sketch,

and with this Position Create a New Part, and then continue with a Creating 3D Model.

 

The Error:

System.InvalidCastException: "The COM object of type 'System.__ComObject' cannot be cast to the interface type 'Inventor.Vertex'. This operation could not be performed because the QueryInterface call to the COM component for the interface with The IID "{5DF8608F-6B16-11D3-B794-0060B0F159EF}" could not be performed due to the following error: Interface not supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."

 

florianwenzelEJNZZ_1-1654092790305.png

 

0 Likes
Message 6 of 12

florian_wenzel
Advocate
Advocate

is possible to Get the Coordinate (x,y,z) from a Selecting Point, Vertex or whatEver, but in Assemby Enviroment?

Then use this to Create a Point with this Coordinate

0 Likes
Message 7 of 12

WCrihfield
Mentor
Mentor
Accepted solution

OK. This information adds more possible object types that you may be selecting, depending on the context that the sketch was generated within (SketchPoint, SketchPoint3D, SketchPointProxy, SketchPoint3DProxy).  And I don't know if SketchSplineHandle type objects would be select-able using that selection filter or not, but there are 4 variations of those too.  If the sketch and/or its contents were created directly within the main assembly, they may not be proxy objects.  Ultimately you kind of need to know which type of object you are selecting, to be able to use the proper properties of that object, such as a transient Point object.  I suppose you could create a Point type variable with no value, then use a Try...Catch block with several Catch sections within it in an attempt to extract the Point from the various possible object types, then check whether your previously created variable was given a value afterwards.  Or use a series of If...ElseIf...Else...End If type block, in which you use the TypeOf operator to check its Type, then extract the Point in the necessary way for the Type.  It's a hard one to diagnose remotely, without some trial/error testing.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 8 of 12

WCrihfield
Mentor
Mentor

There is a way to extract mouse pointer location type information when working with the MouseEvents object's available Events, but that data is most likely not going to be accurate enough, because of the 2D nature of your model area view pane.  Plus using those Events are not as intuitive or easy to use as you are likely expecting.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 9 of 12

WCrihfield
Mentor
Mentor
Accepted solution

Here is a quickie little utility iLogic rule you can use to quickly identify what type of object you are selecting within the context of an assembly.

Sub Main
	While True
		oPt = PickPoint
		If IsNothing(oPt) Then Exit While
	End While
End Sub

Function PickPoint(Optional oPrompt As String = vbNullString) As Object
	If String.IsNullOrEmpty(oPrompt) Then oPrompt = "Pick a Point"
	oObj = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllPointEntities, oPrompt)
	If IsNothing(oObj) Then Return Nothing
	MsgBox("Picked Point Object TypeName(oObj) = " & TypeName(oObj), , "")
	Return oObj
End Function

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 10 of 12

florian_wenzel
Advocate
Advocate

i was checking all 4 variations (SketchPointSketchPoint3DSketchPointProxySketchPoint3DProxy)

Unfortunately, neither works.

 

 

"SketchPoint"

Dim oPointOriginSet As SketchPoint = g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kAllPointEntities, "Pick a Point")

Dim oPointOrigin As Point
oPointOrigin = oPointOriginSet.Geometry3d

 

"SketchPoint3D"

Dim oPointOriginSet As SketchPoint3D = g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kAllPointEntities, "Pick a Point")

Dim oPointOrigin As Point
oPointOrigin = oPointOriginSet.Geometry

 

"SketchPointProxy"

Dim oPointOriginSet As SketchPointProxy = g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kAllPointEntities, "Pick a Point")

Dim oPointOrigin As Point
oPointOrigin = oPointOriginSet.Geometry3d

 

"SketchPoint3DProxy"

Dim oPointOriginSet As SketchPoint3DProxy = g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kAllPointEntities, "Pick a Point")

Dim oPointOrigin As Point
oPointOrigin = oPointOriginSet.Geometry

 

 

The Sketch in Assembly was Creating with Mouse normaly, Native. Simple Projecting the Outside Edges on A Offset WorkPlane. As a Sketch 2d.

I Think in a Assembly you are able to Create only 2dSketch or ?

0 Likes
Message 11 of 12

florian_wenzel
Advocate
Advocate

Hi,

Ilogic info:

florianwenzelEJNZZ_0-1654108782525.pngflorianwenzelEJNZZ_1-1654108806984.png

 

So, it shows that this is SketchPoint, not WorkPoint, and not VertexProxy.

Vertex Proxy, only on 3D Model from Assembly, or other Models

0 Likes
Message 12 of 12

florian_wenzel
Advocate
Advocate

Hi, 

Ok its Working 

florianwenzelEJNZZ_0-1654109840390.png

 

 

Imports System.Runtime.InteropServices
Imports Inventor
Imports Microsoft.Win32

Module CommandFunctionButton_01
    Public Sub CommandFunctionfweButton_01()

        Dim oAsmDoc As AssemblyDocument = g_inventorApplication.ActiveDocument
        Dim oAsmCompDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition


        Dim oTO As TransientObjects = g_inventorApplication.TransientObjects
        Dim oTG As TransientGeometry = g_inventorApplication.TransientGeometry


        Dim oPointOriginSet As SketchPoint = g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kAllPointEntities, "Pick a Point")

        Dim oPointOrigin As Point
        oPointOrigin = oPointOriginSet.Geometry3d




        Dim oXAxis As Vector = oTG.CreateVector(1, 0, 0)
        Dim oYAxis As Vector = oTG.CreateVector(0, 1, 0)
        Dim oZAxis As Vector = oTG.CreateVector(0, 0, 1)


        Dim oMatrix As Matrix = oTG.CreateMatrix
        Call oMatrix.SetCoordinateSystem(oPointOrigin, oXAxis, oYAxis, oZAxis)

        Dim oOcc As ComponentOccurrence = oAsmCompDef.Occurrences.Add("C:\InventorAPI\001\CAD\3D\Part_02.ipt", oMatrix)



    End Sub
End Module

florianwenzelEJNZZ_1-1654109860571.png

 

0 Likes