Jump to content

VBA - Creating Dimension Style


Recommended Posts



I am trying to create a dimension style using VBA Excel. I have a simple code as follows:


Option Explicit

Sub New_Layer()
Dim acadApp As AcadApplication
Dim acadDoc As AcadDocument
Dim mSp As AcadModelSpace
Dim dimstyle As AcadDimStyle
Dim sDim As AcadDimAligned
Dim point1(0 To 2) As Double
Dim point2(0 To 2) As Double
Dim location(0 To 2) As Double

'Check if AutoCAD is open.
On Error Resume Next
Set acadApp = GetObject(, "AutoCAD.Application")
On Error GoTo 0
'If AutoCAD is not opened create a new instance and make it visible.
If acadApp Is Nothing Then
Set acadApp = New AcadApplication
acadApp.Visible = True
End If
'Check if there is an active drawing.
On Error Resume Next
Set acadDoc = acadApp.ActiveDocument
On Error GoTo 0
'No active drawing found. Create a new one.
If acadDoc Is Nothing Then
Set acadDoc = acadApp.Documents.Add
acadApp.Visible = True
End If
Set mSp = acadDoc.ModelSpace

'Dimension points
point1(0) = 0#: point1(1) = 5#: point1(2) = 0#
point2(0) = 6.1: point2(1) = 5: point2(2) = 0#
location(0) = 5#: location(1) = 4.4: location(2) = 0#

'Add dimension
Set sDim = acadDoc.ModelSpace.AddDimAligned(point1, point2, location)

'Set dimension properties
sDim.Color = acByLayer
sDim.ExtensionLineExtend = 0
sDim.Arrowhead1Type = acArrowOblique
sDim.Arrowhead2Type = acArrowOblique
sDim.ArrowheadSize = 0.1
sDim.TextColor = acGreen
sDim.TextHeight = 0.2
sDim.UnitsFormat = acDimLDecimal
sDim.PrimaryUnitsPrecision = acDimPrecisionOne
sDim.TextGap = 0.1
sDim.LinearScaleFactor = 100
sDim.ExtensionLineOffset = 0.1
sDim.VerticalTextPosition = acOutside

'Create a new dimension style
Set dimstyle = acadDoc.DimStyles.Add("D100")

'Copy dimension properties from previously added dimension
dimstyle.CopyFrom (sDim)

'Delete dimension

End Sub



dimstyle.CopyFrom (sDim)

line does not working. I am getting following error: "Object doesn't support this propert or method"


I couldn't find what I am doing wrong. I am using AutoCAD 2013 and Excel 2016.


Thank you!

Link to comment
Share on other sites

Interesting code - it shows the fully activex approach to create dimension style.

I was familiar only with pre-setting certain system variables + command calls, before creating the new dim style.

So that approach was going to be replicated into your code: (vla-SetVariable acaddoc ...) would be used.

Link to comment
Share on other sites

Interesting to look at lisp v's VBA for same task when googled, Grr Setvariable is a supported method in VBA.


Remember seeing a entmake with every variable described somewhere.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...