Jump to content

VBA - Dimension Styles


wannabe

Recommended Posts

Another question from me :)

 

Having created a dimesnion style I want to try and set all of its values. e.g linetype bylayer. However I just can't find the information in the provided help file.

 

thanks in advance

Link to comment
Share on other sites

1. You should draw some dimension (for ex. DIMLINEAR) and set all properties you need for this single dimension.

 

2. Add a new DimensionStyle to the DimensionStyles collection.

 

3. Use method CopyFrom for copy properties from the sample dimension to the DimensionStyle.

 

Current dimension style is only set of system variables which controls new dimensions properties.

Link to comment
Share on other sites

Use a similar syntax as listed below:

ThisDrawing.SetVariable SysvarName, sysVarData

 

where:

SysvarName is the name of the variable you wish to set

sysVarData is the value of the variable

Link to comment
Share on other sites

What I am trying to achiecve is the succesful creation of a new dimesnion style which will have values defined in my VBA macro for:

 

- colour

- Dim Lines Linetype

- Dim Lines Lineweight

- Ext line 1

- Ext Line 2

- Ext Line lineweight

- Extend Beyond Dim lines

- Offset from Origin

 

Still having some difficulty with this.

Link to comment
Share on other sites

If you already have your required Dimension Style setup in a drawing; type in _.sysvdlg at the command line. This will bring up a box with all your system variables in it.

Now the fun bit to filter everything else out, apart from all the variables associated with dimensioning.

In the top box on the left hand side; and before the * type in dim.

Then hit the Save Filtered button; name your file according to something like dim_variables.svf

Using Windows Explorer locate the file you just saved.

Right click on it, and choose Open With.

Try to select Notepad, or some other equivalent editing program.

In the file that is opened you should now see all the variables that are associated with the dimension style.

It should now be a simple process to incorporate all those settings into the sample code I posted earlier in this thread.

Link to comment
Share on other sites

Still having some difficulty with this.

 

Look for my post #2 and this simplified example. It will draw sample aligned dimension in your drawing, creates "Wannabe_DimStyle" dimension style and copy proprties from sample dimension to your dimension style:

 

Sub CreationDimStyle()

Dim mSp As AcadModelSpace
Dim sDim As AcadDimAligned
Dim pt1(0 To 2) As Double
Dim pt2(0 To 2) As Double
Dim tPos(0 To 2) As Double
Dim dCol As AcadDimStyles
Dim nDim As AcadDimStyle

' Set poits to draw dimension
pt1(0) = 0#: pt1(1) = 0#: pt1(2) = 0#
pt2(0) = 0#: pt2(1) = 100#: pt2(2) = 0#
tPos(0) = 50#: tPos(1) = 15#: tPos(2) = 0#

'Get Model Space Collection
Set mSp = ThisDrawing.ModelSpace

' Add new sample aligned dimension
Set sDim = mSp.AddDimAligned(pt1, pt2, tPos)

[color="Blue"]' Set some dimension properties[/color]
sDim.color = 1
sDim.Linetype = "BYBLOCK"
sDim.Lineweight = acLnWt005

' Get DimensionStyles collection
Set dCol = ThisDrawing.DimStyles

' Erase old "Wannabe_DimStyle" dimstyle
On Error Resume Next
dCol.Item("Wannabe_DimStyle").Delete

' Add new "Wannabe_DimStyle" dimstyle
Set nDim = dCol.Add("Wannabe_DimStyle")

[color="#0000ff"]'Copy properties from sample dimension sDim to dimstyle nDim[/color]
nDim.CopyFrom (sDim)

' Delete sample dimension
sDim.Delete

End Sub

 

Look for all dimension properties in Developer Help articles.

Link to comment
Share on other sites

Ok, I am now getting close to my required targets for creating a dimension style; using an aligned dimension to copy the properties from.

 

The problem I have is that I cannot locate any method or code that will allow me to set the linetype of the extension and dimension lines.

 

Everything else is perfect.

Link to comment
Share on other sites

I cannot locate any method or code that will allow me to set the linetype of the extension and dimension lines.

 

Yes this properties missed in Developer Help, therefore if you will look methods and properties of DimAligned in Object Browser you find DimensionLinetype, ExtLine1Linetype and ExtLine2Linetype properties. All used linetypes must be loaded with Load method before you will use it.

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.

Guest
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...