Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
isocam
1016 Views, 2 Replies

Export "DWG" select a face using a VBA macro

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

 

 

andypugh
in reply to: isocam

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? 

Anonymous
in reply to: isocam

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