Jump to content

Using VBA to create Annotative Dim in DimStyle object?


muck

Recommended Posts

Subject: Using VBA to create Annotative Dim in DimStyle object.

AutoCAD 2009 VBA

 

How can someone use VBA make a dimstyle that will

make an annotative dimension?

 

Thank you,

Link to comment
Share on other sites

you have to set the annotative property to true. Let me look for an example

 

Never mind, that was something new for C#, not VBA

Link to comment
Share on other sites

DIMANNO needs to be set to 1

This routines will create a s dim style. I actually have this routine use part the the stylename to set the dimscale and I read stuff from a file I created.

SYSVDLG is a great command to find out what the system variable are currently set to.

I had to strip move of the code down to stay with in the posting rules.

HTH

 

Public Sub MakeDimStyle(stylename As String)

 

' initial variables

Dim objDimStyle As AcadDimStyle

Dim objDimCollection As AcadDimStyles

Dim strDimStyles(2) As String

Dim strWhichSpace As String

Dim strWhichPaper As String

Dim intPos As Integer

Dim sTemp1 As String

Dim strvar As String

Dim varValue As Variant

Dim strValue As String

Dim i As Integer

Dim dbldimscale As Double

Dim lngValue As Long

Dim stemp As String

Dim lenstr As Integer

Dim IntInFile As Integer

Dim file2use As String

 

file2use = Left(stylename, 3) & "0"

 

lenstr = Len(stylename)

dbldimscale = CDbl(Right(stylename, lenstr - 3))

 

On Error Resume Next

Set objDimStyle = ThisDrawing.DimStyles.Item(stylename)

If Err Then

On Error GoTo 0

Set objDimStyle = ThisDrawing.DimStyles.Add(stylename)

 

ThisDrawing.ActiveDimStyle = objDimStyle

 

 

'--- CHANGE YOUR DIM VARIABLE HERE------

ThisDrawing.SetVariable "DIMANNO",1

 

 

 

 

objDimStyle.CopyFrom ThisDrawing

End Sub

Link to comment
Share on other sites

I am wonding about Dimanno being is read only. I am using 2009.

My code uses sendcommand to reset dimanno but I have not

looked at the posted above code.

 

 

Here is my code.

It is at 'Annotation Dim flagged note.

My code is changing dimstyle picking a dimension and

that is my objective in my code. Only way I know how to

do it is to use sendcommnd shown in the last part of my code.

 

Dim objDimension As AcadDimension

Dim varPickedPoint As Variant

Dim objDimStyle As AcadDimStyle

Dim strDimStyles As String

Dim strChosenDimStyle As String

Dim stg As String

 

On Error Resume Next

Me.hide

ThisDrawing.Utility.GetEntity objDimension, varPickedPoint, _

"Picked a dimension whose style you wish to set"

If objDimension Is Nothing Then

MsgBox "You failed to pick a dimension object"

Exit Sub

End If

stg = "Textheight"

ThisDrawing.SetVariable "dimexe", objDimension.ExtensionLineExtend

ThisDrawing.SetVariable "dimexo", objDimension.ExtensionLineOffset

ThisDrawing.SetVariable "DIMCLRD", objDimension.DimensionLineColor

ThisDrawing.SetVariable "DIMCLRE", objDimension.ExtensionLineColor

ThisDrawing.SetVariable "DIMCLRT", objDimension.color

ThisDrawing.SetVariable "Dimscale", objDimension.ScaleFactor

ThisDrawing.SendCommand "Dimscale" & vbCr

ThisDrawing.SendCommand objDimension.ScaleFactor & vbCr

ThisDrawing.SetVariable "DIMTAD", objDimension.VerticalTextPosition

ThisDrawing.SetVariable "DIMTXT", objDimension.TextHeight

ThisDrawing.DimStyles.StyleName , objDimension.TextStyle

ThisDrawing.SetVariable "DIMJUST", objDimension.TextGap

ThisDrawing.SetVariable "DIMASZ", objDimension.ArrowheadSize

ThisDrawing.SetVariable "Clayer", objDimension.Layer

Set objDimStyle = ThisDrawing.DimStyles.Add("YourNamedStyle")

objDimStyle.CopyFrom ThisDrawing

ThisDrawing.ActiveDimStyle = objDimStyle

objDimStyle.CopyFrom ThisDrawing

objDimStyle.Name = "YourNamedStyle"

'Annotation Dim

If objDimension.ScaleFactor = 0 Then

ThisDrawing.SendCommand "-dimstyle" & vbCr & "AN" & vbCr & "Y" & vbCr & "YourNamedStyle" & vbCr & "Y" & vbCr & "s" & vbCr & vbCr

Else

ThisDrawing.SendCommand "-dimstyle" & vbCr & "AN" & vbCr & "N" & vbCr & "YourNamedStyle" & vbCr & "Y" & vbCr & "s" & vbCr & vbCr

End If

ThisDrawing.SetVariable "Dimscale", objDimension.ScaleFactor

ThisDrawing.SendCommand "Dimscale" & vbCr

ThisDrawing.SendCommand objDimension.ScaleFactor & vbCr

Link to comment
Share on other sites

Well, using sendcommand is entirely different than setting dimanno through code. What happens if you type DIMANNO at the command prompt? does it register as readonly?

Link to comment
Share on other sites

In RickyD302's code, what is the line

dbldimscale = CDbl(Right(stylename, lenstr - 3)) for?

 

In that code, I set the dimstyle name to "test1" and it would not get

thru that line?

 

Thank you

Link to comment
Share on other sites

My Bad peoples....When I ran sysvdlg I didn't noticte the read-only. I tried to change DIMANNO to 1 via my code and is just exit my MakeDimStyle routine without error but didn't set it to one either.

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