GeomToDXFCommand Problem

GeomToDXFCommand Problem

Anonymous
Not applicable
620 Views
5 Replies
Message 1 of 6

GeomToDXFCommand Problem

Anonymous
Not applicable
This code:
----- code ----
Call ThisApplication.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, "C:\File.dxf")
Dim oCtrlDef As ControlDefinition
Set oCtrlDef = ThisApplication.CommandManager.ControlDefinitions.Item("GeomToDXFCommand")
Call oCtrlDef.Execute
----- code ----
works fine on VBA (inventor 2008), but when I try making this a Add-in it doesnt work fine.
In a Add-in, it works fine on a OPENED part. It doesnt work on a ACTVATED part inside an assembly.

What is the problem???
0 Likes
621 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
Are you making sure that the correct object (face or sketch) is selected in
the assembly before that code is run? Does the same VBA code work in the
in-place activated case?

Sanjay-
0 Likes
Message 3 of 6

Anonymous
Not applicable
Thanks for the reply Sanjay.

Yes, the real problem was on the selection.

My test code (on a ACTIVATED part inside a assembly):

Dim oPart As PartDocument
Dim oPartCompDef As PartComponentDefinition
Dim oSketch As Sketch
Set oPart=ThisApplication.ActiveDocument.ActivatedObject
Set oPartCompDef=oPart.ComponentDefinition
Set oSketch = oPartCompDef.Sketches.Item("NameOfSketch")
'until now everything is working

Call oPart.SelectSet.Select(oSketch)
'This doesnt select anything (in a activated part), but it works on a part file OPENED

Call ThisApplication.ActiveDocument.SelectSet.Select(oSketch)
'This gives a error msg on VBA: Invalid procedure call or argument.

The funny thing is that if I hand select the sketch and try this code:
Set oSketch = ThisApplication.ActiveDocument.SelectSet.Item(1)
Call ThisApplication.ActiveDocument.SelectSet.Select(oSketch)

I dont get a error msg on VBA...

How can I use the ...SelectSet.Select( ) on a activated part?

Thanks again.
0 Likes
Message 4 of 6

Anonymous
Not applicable
I've solved the case. My problem is the PlanarSketchProxyObject.

When I select something (by hand) on a activated part, I got a ProxyObject. But when I try the ...Select.Select(oSketch) I got the NativeObject.

So, how could I translate the PlanarSketchObject to a PlanarSketchProxyObject in a part activated inside an assembly?

thanks.
0 Likes
Message 5 of 6

Anonymous
Not applicable
You have to find the ComponentOccurrence in the assembly which contains the
sketch of interest and use the ComponentOccurrence.CreateGeometryProxy
method to create a sketch proxy. Note that you have to build a proxy at
every stage in the assembly as you move up the hierarchy. i.e. if the part
is contained directly in the top assembly, you would create the proxy just
once. If it is 2-level deep, you would create one to get a proxy in the
context of the sub-assembly and then use that proxy to create a proxy at the
top level and so on.

The programming help has an overview on proxies, so that may help.

Sanjay-
0 Likes
Message 6 of 6

Anonymous
Not applicable
Finding the ComponentOccurrence in a big assembly (with subassembly) could take some time, so I think the WriteDataToFile is more versatile.

Thanks Sanjay
0 Likes