cagri Posted October 30, 2017 Posted October 30, 2017 Hello, 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 sDim.Delete End Sub However 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! Quote
cagri Posted October 30, 2017 Author Posted October 30, 2017 using dimstyle.CopyFrom sDim instead of dimstyle.CopyFrom (sDim) solved my problem. that was easy. sorry for posting this. Quote
Grrr Posted October 30, 2017 Posted October 30, 2017 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. Quote
BIGAL Posted October 31, 2017 Posted October 31, 2017 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. Quote
Recommended Posts
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.