Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Need Help with Auto Dimension Macro 2

Status
Not open for further replies.

joshF

Industrial
Nov 17, 2021
3
0
0
US
Looking for help on a auto-Dimension Macro. I have the Auto-Dimension Code, But I'd like to add a feature where I pick the corner (vertex) to be a zero.

Right now it defaults to the bottom/left hand corner. (which is not always ideal)

Can anyone help me with selecting a Vertex in the a drawing view and making this the Zero point for ordinate dimensions?

Code:
[indent]Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
'Dim swmodel As SldWorks.ModelDoc2

Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long

Sub main()

Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Part.ClearSelection2 True
boolstatus = Part.ActivateSheet("Sheet1")
boolstatus = Part.ActivateView("Drawing View1")

'vertical
boolstatus = Part.Extension.SelectByID2("Drawing View1", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByRay(0.109400029853413, 0.130434382958623, 6.34999999999764E-03, 0, 0, -1, 1.28866875828181E-03, 1, True, 4, 0)
longstatus = Part.AutoDimension(1, 2, 1, 2, -1)

'Horizontal
boolstatus = Part.Extension.SelectByID2("Drawing View1", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByRay(8.28686142417286E-02, 0.106556108908108, 6.34999999988395E-03, 0, 0, -1, 1.28866875828181E-03, 1, False, 0, 0)
longstatus = Part.AutoDimension(1, 2, 1, 2, -1)

End Sub[/indent]

macro_help_ri5lwi.jpg



 
Replies continue below

Recommended for you

Hello,

See if this works for you.

Insert a sketch point in 'Drawing View3' at the desired point. Select the sketch point. (Make sure that no other object is selected.)

Then run the following code.

Code:
Option Explicit

Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
'Dim swmodel As SldWorks.ModelDoc2

Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long

Sub main()

    Set swApp = Application.SldWorks
    Set Part = swApp.ActiveDoc
        
    'Horizontal

    Dim thePT As Object
    Set thePT = Part.SelectionManager.GetSelectedObject6(1, -1)
    ''''' Select the sketchpoint
    
    '''''''''''''''''
    Dim sData As SelectData
    
    Set sData = Part.SelectionManager.CreateSelectData
    
    sData.Mark = swAutodimMark_e.swAutodimMarkOriginDatum
    '''' See help for details.
    
    Call thePT.Select4(False, sData)
    '''''''''''''''''
    
    ''''''''''''''''''''''
    ''''' This code must be after Sketchpoint is processed. Otherwise sketchpoint gets unselected.
    
    boolstatus = Part.ActivateSheet("Sheet1")
    boolstatus = Part.ActivateView("Drawing View3")
    boolstatus = Part.Extension.SelectByID2("Drawing View3", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)
    
    ''''''''''''''''
    
    longstatus = Part.AutoDimension(1, 2, 1, 2, -1)

End Sub

 
Status
Not open for further replies.
Back
Top