Get Template Anchor Points

Programming and macros
User avatar
mihkov
Posts: 44
Joined: Sun Feb 05, 2023 2:01 am
Answers: 0
x 17
x 24

Get Template Anchor Points

Unread post by mihkov »

I want to insert a block into a drawing so that the block falls into one of the anchor points for the tables.
For example, to the anchor point for "Holes table anchor1". How can I get these pre-arranged points on a drawing template?
I thought about inserting the block itself using: MakeSketchBlockFromFile
Accordingly, I need to convert the anchor point to a MathPoint

Dim instance As ISketchManager
Dim InsertionPoint As MathPoint
Dim FileName As System.String
Dim LinkedToFile As System.Boolean
Dim Scale As System.Double
Dim Angle As System.Double
Dim value As SketchBlockDefinition

value = instance.MakeSketchBlockFromFile(InsertionPoint, FileName, LinkedToFile, Scale, Angle)

GetAnchorPoint.png
by RonE » Mon Jun 10, 2024 4:49 am Go to full post
User avatar
RonE
Posts: 32
Joined: Wed Nov 17, 2021 10:02 am
Answers: 4
Location: Germany
x 18
x 33

Re: Get Template Anchor Points

Unread post by RonE »

User avatar
mihkov
Posts: 44
Joined: Sun Feb 05, 2023 2:01 am
Answers: 0
x 17
x 24

Re: Get Template Anchor Points

Unread post by mihkov »

RonE wrote: Mon Jun 10, 2024 4:49 am TableAnchor Property (ISheet) (https://help.solidworks.com/2024/englis ... nchor.html) -> Position Property (ITableAnchor) (https://help.solidworks.com/2024/englis ... ition.html)
Yes, this is what I need. I found a solution after searching for a while. Here is the code that reloads the Drawing Template and adds a block to the Anchor point for the HoleChart in that Template.

Code: Select all

Const SomeBlocPatch As String =  "Y:\FlatBloc2_sheet.SLDBLK"
Dim swApp As Object
Dim swDoc As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim holeTableAnchor As TableAnchor
Dim sketchManager As SldWorks.sketchManager
Dim swMathUtility As SldWorks.MathUtility
Dim swMathPoint As SldWorks.MathPoint
Dim pointsArray(2) As Double

Sub main()

Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc
If Not swModel Is Nothing Then
    If swModel.GetType() = swDocumentTypes_e.swDocDRAWING Then
        Set swDraw = swDoc
        Dim swDrawSheet As Sheet
        Set swDrawSheet = swDraw.GetCurrentSheet
                Dim Ans As Integer
        Ans = swDrawSheet.ReloadTemplate(False)  'True to keep note modifications made to the sheet format and reload all other elements from the original sheet format template, false to reload all elements from the original sheet format template and discard any note modifications made to the sheet format
        'Ans 0:Success;1:UnknownError;2:FileNotFound;3:CustomSheet;4:ViewOnly;
                Set sketchManager = swDoc.sketchManager
                If Not sketchManager Is Nothing Then
'TableAnchor(TableType)   TableType:
'0-General;
'1-HoleChart;
'2-BillOfMaterials;
'3-RevisionBlock;
'4-WeldmentCutList;
'5-TitleBlock;
'6-WeldTable;
'7-BendTable;
'8-PunchTable;
'9-GeneralTolerance
                        Set holeTableAnchor = swDrawSheet.TableAnchor(1)
                        If Not holeTableAnchor Is Nothing Then
                            Dim anchorPosition As Variant
                            anchorPosition = holeTableAnchor.Position
                            Set swMathUtility = swApp.GetMathUtility
                            pointsArray(0) = anchorPosition(0): pointsArray(1) = anchorPosition(1): pointsArray(2) = 0 'x y and z = 0
                            Set swMathPoint = swMathUtility.CreatePoint(pointsArray)
                                If Not swMathPoint Is Nothing Then
                                    swDraw.EditTemplate
                                    Dim myBlockDefinition As Object
                                    Set myBlockDefinition = sketchManager.MakeSketchBlockFromFile(swMathPoint, SomeBlocPatch, False, 1, 0)
                                    swDraw.EditSheet
                                End If
                        End If
                Else
                    MsgBox "Failed to get SketchManager."
                End If
    Else
        MsgBox "The active document is not a drawing. Bye Bye"
    End If
Else
    MsgBox "There is no active document."
End If
End Sub
Post Reply