Jump to content
ksperopoulos

Create Dimension Style Using Visual Lisp?

Recommended Posts

ksperopoulos

Is there a way to create a dimension style via Visual LISP instead of AutoLISP? It seems like the only way I can find is by setting variables instead of properties (similar to how one can with layers, text styles, etc.).

Share this post


Link to post
Share on other sites
Tharwat

Hi,

An abstract example. :)

 

(vla-add (vla-get-dimstyles (vla-get-activedocument (vlax-get-acad-object))) "New Dim")

Share this post


Link to post
Share on other sites
Lee Mac

The Visual LISP route will still involve configuring system variables and then using the copyfrom method.

Share this post


Link to post
Share on other sites
ksperopoulos

Thank you for your response. I should have been more clear. I already have been able to add the style to the collection via vla-add, I am more interested though in setting the properties associated with the style.

Share this post


Link to post
Share on other sites
ksperopoulos
The Visual LISP route will still involve configuring system variables and then using the copyfrom method.

 

Thank you Lee. That's what I thought. I just wanted to make sure I was headed down the right path if I chose to go with VL.

Share this post


Link to post
Share on other sites
ksperopoulos

I placed a dimensions using my dimension style in a drawing. I then did a vlax-dump-object on that it to see what it returned. I came up with a long list of information that seems like I would be able to use for creating the dimstyle. Can these properties be applied to a dimstyle or can they only be applied to an existing dimension in a drawing?

 

; IAcadDimRotated: AutoCAD Rotated Dimension Interface
; Property values:
;   AltRoundDistance = 0.0
;   AltSubUnitsFactor = 100.0
;   AltSubUnitsSuffix = ""
;   AltSuppressLeadingZeros = 0
;   AltSuppressTrailingZeros = 0
;   AltSuppressZeroFeet = -1
;   AltSuppressZeroInches = -1
;   AltTextPrefix = ""
;   AltTextSuffix = ""
;   AltTolerancePrecision = 2
;   AltToleranceSuppressLeadingZeros = 0
;   AltToleranceSuppressTrailingZeros = 0
;   AltToleranceSuppressZeroFeet = -1
;   AltToleranceSuppressZeroInches = -1
;   AltUnits = 0
;   AltUnitsFormat = 2
;   AltUnitsPrecision = 2
;   AltUnitsScale = 25.4
;   Application (RO) = #<VLA-OBJECT IAcadApplication 00007ff7b8dfa130>
;   Arrowhead1Block = "ArchTick"
;   Arrowhead1Type = 4
;   Arrowhead2Block = "ArchTick"
;   Arrowhead2Type = 4
;   ArrowheadSize = 0.09375
;   DecimalSeparator = "."
;   DimConstrDesc = Exception occurred
;   DimConstrExpression = Exception occurred
;   DimConstrForm = 0
;   DimConstrName = Exception occurred
;   DimConstrReference = 0
;   DimConstrValue = Exception occurred
;   DimensionLineColor = 256
;   DimensionLineExtend = 0.0625
;   DimensionLinetype = "Continuous"
;   DimensionLineWeight = 25
;   DimLine1Suppress = 0
;   DimLine2Suppress = 0
;   DimLineInside = 0
;   DimTxtDirection = 0
;   Document (RO) = #<VLA-OBJECT IAcadDocument 000000bfffb0abd8>
;   EntityTransparency = "ByLayer"
;   ExtensionLineColor = 256
;   ExtensionLineExtend = 0.0625
;   ExtensionLineOffset = 0.0625
;   ExtensionLineWeight = 25
;   ExtLine1Linetype = "Continuous"
;   ExtLine1Suppress = 0
;   ExtLine2Linetype = "Continuous"
;   ExtLine2Suppress = 0
;   ExtLineFixedLen = 1.0
;   ExtLineFixedLenSuppress = 0
;   Fit = 3
;   ForceLineInside = 0
;   FractionFormat = 2
;   Handle (RO) = "A73B"
;   HasExtensionDictionary (RO) = -1
;   HorizontalTextPosition = 0
;   Hyperlinks (RO) = #<VLA-OBJECT IAcadHyperlinks 000000bfaf276a38>
;   Layer = "0"
;   LinearScaleFactor = 1.0
;   Linetype = "ByLayer"
;   LinetypeScale = 1.0
;   Lineweight = -1
;   Material = "ByLayer"
;   Measurement (RO) = 940.458
;   Normal = (0.0 0.0 1.0)
;   ObjectID (RO) = 42
;   ObjectName (RO) = "AcDbRotatedDimension"
;   OwnerID (RO) = 43
;   PlotStyleName = "ByLayer"
;   PrimaryUnitsPrecision = 3
;   Rotation = 0.0
;   RoundDistance = 0.0
;   ScaleFactor = 1.0
;   StyleName = "MMC"
;   SubUnitsFactor = 100.0
;   SubUnitsSuffix = ""
;   SuppressLeadingZeros = 0
;   SuppressTrailingZeros = 0
;   SuppressZeroFeet = -1
;   SuppressZeroInches = 0
;   TextColor = 256
;   TextFill = 0
;   TextFillColor = 0
;   TextGap = 0.0625
;   TextHeight = 0.09375
;   TextInside = 0
;   TextInsideAlign = 0
;   TextMovement = 0
;   TextOutsideAlign = 0
;   TextOverride = ""
;   TextPosition = (-1843.13 1512.41 0.0)
;   TextPrefix = ""
;   TextRotation = 0.0
;   TextStyle = "MMC"
;   TextSuffix = ""
;   ToleranceDisplay = 0
;   ToleranceHeightScale = 1.0
;   ToleranceJustification = 1
;   ToleranceLowerLimit = 0.0
;   TolerancePrecision = 3
;   ToleranceSuppressLeadingZeros = 0
;   ToleranceSuppressTrailingZeros = 0
;   ToleranceSuppressZeroFeet = -1
;   ToleranceSuppressZeroInches = -1
;   ToleranceUpperLimit = 0.0
;   TrueColor = #<VLA-OBJECT IAcadAcCmColor 000000bfb5b704e0>
;   UnitsFormat = 4
;   VerticalTextPosition = 1
;   Visible = -1

Share this post


Link to post
Share on other sites
BIGAL

Had a quick look at my R12 lisp manual the paper one and there is close to 2 pages of dxf codes for making a dimstyle, so yes you should be able to change either 1 dim or alter a dimstyle. Tharwats code opens up the dim styles just need next step to get at each one I was doing something wrong when trying a dump.

Share this post


Link to post
Share on other sites
ksperopoulos

You may not have been doing anything wrong when you tried dumping the dimstyle. If you dump an existing dimstyle object or the dimstyle object added to the collection per the code Tharwat is demonstrating, you only get a little information returned. If you set the variables like Lee mentions above, that is how you can edit all the settings of a dimstyle. Just out of curiosity, I thought I would place a dimension in my drawing and do a dump on the entity. The above list is what is returned. I was hoping these might provide another avenue of modifying a dimension style.

Share this post


Link to post
Share on other sites
BIGAL

Getting their slowly a bit of a google you can only edit the current dimstyle so use copyfrom then set properties, which is what Lee was suggesting

 

(setq dims (vla-get-activedimstyle (vla-get-activedocument (vlax-get-acad-object))))
(vla-put-name dims "BIGAL") ; renames your current dim style
; just use what you dumped above

Share this post


Link to post
Share on other sites
ksperopoulos

I think you, Lee, and I are all saying the same thing, but I was just looking at a different way of writing the code. I really like how easy it is to read visual lisp code. It may use longer function names, property names, etc., but when reading it, I can figure out what I did a lot quicker. So I was looking to incorporate this method with creating a dimension style from scratch. I now understand that you can only modify the properties of the current dimension style. I also understand that those properties can only be modified by setting each individual variable similar to this:

 

(vla-setvariable doc "DIMCLRD" 256)

 

However, I was hoping to do something more along the lines of this:

 

(vlax-put-property dimobj "DimensionLineColor" 256)

Share this post


Link to post
Share on other sites
Lee Mac
However, I was hoping to do something more along the lines of this:

(vlax-put-property dimobj "DimensionLineColor" 256)

 

This is possible: note that any Dimension object may constitute the SourceObject argument when the copyfrom method is applied to a Dimension Style.

 

Hence you can configure the appropriate properties for a representative Dimension object, and then copy such properties to your Dimension Style using the copyfrom method.

Share this post


Link to post
Share on other sites
ksperopoulos

I'm curious why we have to create a new style and configure all the settings, only to copy all of it to another style? Do you then have to delete the style you copy everything from? Or am I completely off target? :?

Share this post


Link to post
Share on other sites
Lee Mac

Please note that I refer to a Dimension Object, not Dimension Style Object as the SourceObject argument.

Share this post


Link to post
Share on other sites
ksperopoulos

Oh. So does a dimension object have to be something visible in the drawing or can it be stored in the background?

Share this post


Link to post
Share on other sites
Lee Mac
Oh. So does a dimension object have to be something visible in the drawing or can it be stored in the background?

 

It could be temporarily created, configured (using the ActiveX properties you referred to in your earlier post), copied from (using vla-copyfrom), and then deleted.

Share this post


Link to post
Share on other sites
ksperopoulos

So theoretically, it is the same either way. I either create an extra dimstyle and then delete it once I am done or I create a dimension and delete it once I am done?

Share this post


Link to post
Share on other sites
Lee Mac
So theoretically, it is the same either way. I either create an extra dimstyle and then delete it once I am done or I create a dimension and delete it once I am done?

 

No, there is no need to create an extra Dimension Style. Earlier in this thread, you were looking to control the properties of a Dimension Style using the ActiveX properties that are available for a Dimension Object (the properties that you have listed in your earlier post). This is indeed possible by creating a temporary Dimension Object (with any Dimension Style), configuring the necessary properties of the dimension, and then using the copyfrom method to apply such properties to your new Dimension Style, before deleting the temporary Dimension Object.

Share this post


Link to post
Share on other sites
ksperopoulos

I'm sorry if I am confusing everyone. It's not my intention. I am just trying to wrap my head around it. I will try to be a little more clear.

 

Task:

 

If I open a drawing and there are no dimension objects in that drawing and my particular dimstyle is not in that drawing, then I want to create my dimstyle.

 

Question:

  1. Can I create my dimstyle through properties (e.g. (vlax-put-property dimobj "DimensionLineColor" 256)) or do I have to create the dimstyle through setting variables (e.g. (vla-setvariable doc "DIMCLRD" 256))?
  2. If I can create it through properties, do I have to first create a dimension object within my drawing file and configure its properties before I can copy them to my dimstyle using the copyfrom method? And then do I delete the dimension object from my file?
  3. If I can create it through setting variables, do I have to first create a "dummy" dimstyle within my drawing file and configure its properties before I can copy them to my "real" dimstyle using the copyfrom method? And then do I delete the "dummy" dimstyle from my file?

 

Edit: I got my answers by reading the help file and everyone's comments in this thread over and over and over and over again. Like Lee points out - I can create a dimstyle by setting variables and using the copyfrom method. I was having so many issues with this because I was trying to copy from one dimstyle to another dimstyle. By doing it this way, I couldn't get the overrides to copy over. I finally figured out you have to copy the dimension collection to the dimstyle.

 

(vl-load-com)
(setq acadobj (vlax-get-acad-object))
(setq doc (vla-get-activedocument acadobj))
(setq dimcoll (vla-get-dimstyles doc))
(setq dimname "[i][color="red"]dimstylename[/color][/i]")
(setq dimobj (vla-add dimcoll dimname))
(vla-put-activedimstyle doc dimobj)
(vla-setvariable doc "[i][color="red"]variable[/color][/i]" [i][color="red"]variablevalue[/color][/i])
(vla-copyfrom dimobj dimcoll)

Edited by ksperopoulos
I'm dumb!

Share this post


Link to post
Share on other sites
rkmcswain

Unless I missed it, what is the opposition to just creating it using plain autolisp?

Just curious.

Share this post


Link to post
Share on other sites
Lee Mac

To throw another option into the mix, you could also import the Dimension Style from a template/supporting drawing using ObjectDBX - no configuration necessary.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×