Export "DWG" select a face using a VBA macro

Export "DWG" select a face using a VBA macro

isocam
Collaborator Collaborator
1,057 Views
2 Replies
Message 1 of 3

Export "DWG" select a face using a VBA macro

isocam
Collaborator
Collaborator

Can anybody help????

 

I have the following code that outputs an AutoCAD "Dwg" file of an extruded face. The output is a 2d profile.

 

        Dim oDoc As PartDocument

        Set oDoc = ThisApplication.ActiveDocument

        Dim oBaseFace As Face

        Set oBaseFace = oDoc.SelectSet.Item(1): THIS IS THE PROBLEM LINE!!!!

        Dim Cm As CommandManager

        Set Cm = ThisApplication.CommandManager

        Call Cm.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent,"C:\Test.dwg")

        Dim oCtrlDef As ButtonDefinition

        Set oCtrlDef = ThisApplication.CommandManager.ControlDefinitions.Item("GeomToDXFCommand")

        Call oCtrlDef.Execute

 

It works fine but I have to pre-select the face of the extrusion manually before running the macro. Does anybody know how to automatically select the face using the VBA macro rather than manually selecting the face first?

 

All I am doing is creating a sketch (Lines/Arcs/Circles) then extruding the sketch. Nothing else!

 

Many thanks in advance!!!!

 

Darren

 

 

0 Likes
1,058 Views
2 Replies
Replies (2)
Message 2 of 3

andypugh
Enthusiast
Enthusiast

I think that you can do this without a macro, I seem to recall a right-click option to export a face. 

(I am waiting for re-installation on a new PC so can't check today). 

 

Your VBA should be able to iterate through all faces and choose one, but how will it know which one you intended to export? 

0 Likes
Message 3 of 3

Anonymous
Not applicable

May be:

 

SyntaxEditor Code Snippet

 Dim testFace As Face 
                
                 Try
                 testFace = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select a face") 
                 Catch  ex As Exception
                 End Try
            
                    If (testFace Is Nothing) Then
                        Return
                    End If
0 Likes