Hide Table of Contents

Get Labels of Datum Origin Example (VBA)

This example shows how to get the labels of a datum origin.

'--------------------------------------------------------------
' Preconditions:
' 1. Verify that the specified files exist:
'    * part document
'    * drawing document template
'    * hole table template
' 2. Open the Immediate window.
'
' Postconditions:
' 1. Opens the specified part document.
' 2. Creates a drawing of the part document.
' 3. Inserts a hole table annotation at the specified vertex.
' 4. Gets the hole table and its datum origin.
' 5. Prints the datum origin's x and y labels to the Immediate
'    window.
' 6. Examine the Immediate window and drawing.
'---------------------------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDrawingDoc As SldWorks.DrawingDoc
Dim swView As SldWorks.View
Dim swModelView As SldWorks.ModelView
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swSelectionMgr As SldWorks.SelectionMgr
Dim swHoleTableAnnotation As SldWorks.HoleTableAnnotation
Dim swHoleTable As SldWorks.HoleTable
Dim swDatumOrigin As SldWorks.DatumOrigin
Dim fileName As String
Dim drawingDocTemplate As String
Dim holeTableTemplate As String
Dim status As Boolean
Dim errors As Long
Dim warnings As Long
Sub main()
    Set swApp = Application.SldWorks    
    'Open part document and create drawing document
    fileName = "C:\Program Files\SolidWorks Corp\SolidWorks\samples\tutorial\tolanalyst\minimum_clearance\top_plate.sldprt"
    Set swModel = swApp.OpenDoc6(fileName, swDocumentTypes_e.swDocPART, swOpenDocOptions_e.swOpenDocOptions_Silent, "", errors, warnings)
    drawingDocTemplate = "C:\ProgramData\SolidWorks\SolidWorks 2015\templates\Drawing.drwdot"
    Set swDrawingDoc = swApp.NewDocument(drawingDocTemplate, swDwgPaperSizes_e.swDwgPaperBsize, 0.2794, 0.4318)
    Set swView = swDrawingDoc.CreateDrawViewFromModelView3(fileName, "*Front", 0.193046827497194, 0.155595183164983, 0)
    'Insert hole table annotation
    Set swModel = swApp.ActiveDoc
    Set swDrawingDoc = swModel
    Set swModelView = swModel.ActiveView
    Set swModelDocExt = swModel.Extension
    status = swDrawingDoc.ActivateView("Drawing View1")
    status = swModelDocExt.SelectByID2("", "VERTEX", 0.216278249046016, 0.198389907070707, 8.0000000000382E-03, False, 0, Nothing, 0)
    status = swModelDocExt.SelectByID2("", "FACE", 0.228097744219978, 0.151927063973064, 4.0000000000191E-03, False, 0, Nothing, 0)
    swModel.ClearSelection2 True
    status = swModelDocExt.SelectByID2("", "VERTEX", 0.216278249046016, 0.198389907070707, 8.0000000000382E-03, True, 1, Nothing, 0)
    status = swModelDocExt.SelectByID2("", "FACE", 0.228097744219978, 0.151927063973064, 4.0000000000191E-03, True, 2, Nothing, 0)
    Set swSelectionMgr = swModel.SelectionManager
    Set swView = swSelectionMgr.GetSelectedObjectsDrawingView2(1, -1)
    holeTableTemplate = "C:\Program Files\SolidWorks Corp\SolidWorks\lang\english\standard hole table--letters.sldholtbt"
    Set swHoleTableAnnotation = swView.InsertHoleTable2(False, 5.40658670033671E-02, 0.253819263748597, 1, "A", holeTableTemplate)
    swModel.ClearSelection2 True    
    'Get hole table and its datum origin
    Set swHoleTable = swHoleTableAnnotation.HoleTable
    Set swDatumOrigin = swHoleTable.DatumOrigin    
    'Get datum origin's x and y labels
    Debug.Print "Datum origin:"
    Debug.Print ("  X label: " & swDatumOrigin.XLabel)
    Debug.Print ("  Y label: " & swDatumOrigin.YLabel)
End Sub


Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Get Labels of Datum Origin Example (VBA)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:

x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2015 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.