Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

where am I wrong? create a sketch on a selected Face

3 REPLIES 3
Reply
Message 1 of 4
ewighell
346 Views, 3 Replies

where am I wrong? create a sketch on a selected Face

First the program let the user select a Face, and then the program will build a sketch on the Face.
if this work is performed under the part environment, every thing is OK. but it dose not work under the Assembly environment in which a single component part has been activated. I find through debugging that error occurs when the program hit the last line of the following code, after which I give the error code and its meaning.
following is the code and I leave out the error handling part for clarity and simplicity.
-------------------------------------------
HRESULT CDieDesignDlg::OnSelect1( ObjectsEnumerator * JustSelectedEntities, SelectionDeviceEnum SelectionDevice,Point * ModelPosition, Point2d * ViewPosition, View * View)
{
CComPtr pObject;
hr = JustSelectedEntities->get_Item(1, &pObject);
CComQIPtr pFace(pObject);
CComPtr pSurfaceBody;
hr = pFace->get_Parent(&pSurfaceBody);
CComPtr pComponentDefinition;
hr = pSurfaceBody->get_ComponentDefinition (&pComponentDefinition);
//build a sketch on the face just selected
CComQIPtr pPartCompoDef(pComponentDefinition);
CComPtr pSketchs;
pPartCompoDef->get_Sketches(&pSketchs);
CComPtr pPlanarSketch
hr = pSketchs->Add(pFace,VARIANT_FALSE,&pPlanarSketch);//error code:-2147024809:参数不正确
}
--------------------------------------------

dose any body have any idea where I am wrong? any idea will be appreciated, thank you very much!
3 REPLIES 3
Message 2 of 4
Anonymous
in reply to: ewighell

The problem is that the object being returned when an assembly is active is
different than when a part is active. When the Face is selected when the
part is active you get back a Face object. When an assembly is active you
get back a FaceProxy object. This represents the face as if it exists in
the assembly. I believe all you need to do to get your code to work is when
you get back a FaceProxy object is to call the NativeObject property of the
FaceProxy. This will return that actual Face object within the Part. You
should then be able to create the sketch.
--
Brian Ekins
Autodesk Consulting

wrote in message news:5058169@discussion.autodesk.com...
First the program let the user select a Face, and then the program will
build a sketch on the Face.
if this work is performed under the part environment, every thing is OK. but
it dose not work under the Assembly environment in which a single component
part has been activated. I find through debugging that error occurs when
the program hit the last line of the following code, after which I give the
error code and its meaning.
following is the code and I leave out the error handling part for clarity
and simplicity.
-------------------------------------------
HRESULT CDieDesignDlg::OnSelect1( ObjectsEnumerator * JustSelectedEntities,
SelectionDeviceEnum SelectionDevice,Point * ModelPosition, Point2d *
ViewPosition, View * View)
{
CComPtr pObject;
hr = JustSelectedEntities->get_Item(1, &pObject);
CComQIPtr pFace(pObject);
CComPtr pSurfaceBody;
hr = pFace->get_Parent(&pSurfaceBody);
CComPtr pComponentDefinition;
hr = pSurfaceBody->get_ComponentDefinition (&pComponentDefinition);
//build a sketch on the face just selected
CComQIPtr pPartCompoDef(pComponentDefinition);
CComPtr pSketchs;
pPartCompoDef->get_Sketches(&pSketchs);
CComPtr pPlanarSketch
hr = pSketchs->Add(pFace,VARIANT_FALSE,&pPlanarSketch);//error
code:-2147024809:?????
}
--------------------------------------------

dose any body have any idea where I am wrong? any idea will be appreciated,
thank you very much!
Message 3 of 4
ewighell
in reply to: ewighell

thank you brian
Message 4 of 4
MariuszZ
in reply to: ewighell

I have a similar problem. In my macro, when I select a face on the part (in assembly) I  gets Faceproxy object. According to Brian instruction, to create a sketch in the new part I use the NativeObject and ...

does not workSmiley Sad  

What am I doing wrong?

Here is my code:

 

 

' Check to make sure a Assembly document is active.
If ThisApplication.ActiveDocumentType <> kAssemblyDocumentObject Then
MsgBox "A assembly document must be active."
Exit Sub
End If

' Set a reference to the active document.
Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument

'Select Face in Assembly
Dim oSelect As New clsSelect
Dim oFace As face
Set oFace = oSelect.Pick(kPartFaceFilter) 'kWorkPlaneFilter
Dim oNativeFace As face
If oFace Is Nothing Then
Exit Sub
Else
Set oNativeFace = oFace.NativeObject
End If

'Create the new part
Dim oPart As PartDocument
Set oPart = ThisApplication.Documents.Add(kPartDocumentObject, ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject), False)
oPart.FullFileName = Mid(oDoc.FullFileName, 1, InStrRev(oDoc.FullFileName, "\")) & "InB-1.ipt"

' Set a reference to the transient geometry object.
Dim oTG As TransientGeometry
Set oTG = ThisApplication.TransientGeometry

'Insert the part into the assembly using a somewhat 0 position.
Set oMatrix = oTG.CreateMatrix
Call oMatrix.Translation.AddVector(oTG.CreateVector(0, 0, 0))
Call oMatrix.SetToRotation(0, oTG.CreateVector(0, 0, 0), oTG.CreatePoint(0, 0, 0))

Dim oOcc As ComponentOccurrence
Set oOcc = oDoc.ComponentDefinition.Occurrences.AddByComponentDefinition(oPart.ComponentDefinition, oMatrix)

Dim oSketch As PlanarSketch
Set oSketch = oPart.ComponentDefinition.Sketches.Add(oNativeFace, True)

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report