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

VBA macro

sandreev
Explorer

VBA macro

sandreev
Explorer
Explorer

Hello guys,

I'm quite inexperienced with VBA so if any of you can help me get this macro to work will be very much appreciated. I am trying to extract X Y Z of work points in the 3D model and create a General table into a drawing with the info, 1st column to be with the name of the work point, 2nd column empty, the rest are X Y Z. It's highlighting the last row but I don't know how to fix it 

 

Set oCustomTable = oSheet.CustomTables.Add("", ThisApplication.TransientGeometry.CreatePoint2d(15, 15), 5, oSheet.Centermarks.Count, oTitles, oContents, oColumnWidths)

 

The whole code is this

 

Public Sub CreateGLOBALtest()
' Set a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument

' Set a reference to the active sheet.
Dim oSheet As Sheet
Set oSheet = oDrawDoc.ActiveSheet


' Set the column titles
Dim oTitles(1 To 5) As String
oTitles(1) = "RPS"
oTitles(2) = "Note"
oTitles(3) = "X (mm)"
oTitles(4) = "Y (mm)"
oTitles(5) = "Z (mm)"


' Set the contents of the custom table (contents are set row-wise)
Dim oCenterMark As Centermark
Dim oPoint As Point
Dim i As Integer
i = oSheet.Centermarks.Count * 5
ReDim oContents(1 To i) As String
i = 1

For Each oCenterMark In oDrawDoc.ActiveSheet.Centermarks
Set oPoint = oCenterMark.ModelWorkFeature.Point
oContents(i) = oCenterMark.ModelWorkFeature.Name
i = i + 2
oContents(i) = Round((oPoint.X * 10), 10)
i = i + 1
oContents(i) = Round((oPoint.Y * 10), 10)
i = i + 1
oContents(i) = Round((oPoint.Z * 10), 10)
i = i + 1
'Debug.Print oPoint.X & ", " & oPoint.Y & ", " & oPoint.Z
Next

' Set the column widths (defaults to the column title width if not specified)
Dim oColumnWidths(1 To 5) As Double
oColumnWidths(1) = 3
oColumnWidths(2) = 6
oColumnWidths(3) = 2.3
oColumnWidths(4) = 2.3
oColumnWidths(5) = 2.3

' Create the custom table
Dim oCustomTable As CustomTable
Set oCustomTable = oSheet.CustomTables.Add("", ThisApplication.TransientGeometry.CreatePoint2d(15, 15), 5, oSheet.Centermarks.Count, oTitles, oContents, oColumnWidths)


End Sub

 

Thanks in advance!

0 Likes
Reply
Accepted solutions (1)
531 Views
1 Reply
Reply (1)

Mark.Lancaster
Consultant
Consultant
Accepted solution

@sandreev 

 

When it comes to programming needs for Inventor use the Inventor Customization forum for that https://forums.autodesk.com/t5/inventor-customization/bd-p/120

 

I will request your posting to be relocated there to best suit your needs.

Mark Lancaster


  &  Autodesk Services MarketPlace Provider


Autodesk Inventor Certified Professional & not an Autodesk Employee


Likes is much appreciated if the information I have shared is helpful to you and/or others


Did this resolve your issue? Please accept it "As a Solution" so others may benefit from it.

0 Likes