Hello everyone,
I'm currently facing a challenge with AutoCAD (version 2024) that I hope to solve with your expertise. I work extensively with different dimension styles (Dimstyles) in my drawings, and each of these styles is supposed to be associated with a specific layer. I am an apprentice, and when I ask for help, my coworkers don't even know what AutoLISP is.
For instance, dimensions with the style "COTE5" should automatically be placed on the layer "COT_DET_5".
However, the process I'm using requires manual selection of both the dimension style and its corresponding layer, which is quite time-consuming and prone to errors. My goal is to automate this process: when I draw dimensions using a specific style, I want AutoCAD to automatically assign the corresponding layer to these dimensions.
I've attempted to create an AutoLISP with ChatGpt but is not very effective and my understanding is very basic.
Here's a summary of what I'm trying to achieve:
1. Monitor when a dimension is drawn.
2. Check the dimension style of the newly drawn dimension.
3. Change the layer of the dimension to the predefined layer associated with that style.
I'm aware that is probably something that's is already done but i could'nt find a proper clue.
Could anyone provide guidance on how to approach this problem, or share if you've tackled similar automation tasks in AutoCAD? Any sample scripts or pointers to relevant AutoLISP functions and methodologies would be greatly appreciated.
Thank you in advance for your help and suggestions!
David
@pb01eah wrote:
Thank you for your suggestions. I've tried using DIMLAYER, but this sets the layer for all dimensions globally...
Well, not quite in your case: since you jump around different dimstyles before creating dimensions, the process of selecting the dimstyle coincides with with the dimlayer change too. One follows the other every single time.
And if you have a different dimension styles for each plot scale, don't you also have a need to change text styles every time you change plotscales too? How are those handled, don't they also need to be on separate layers corresponding to plot scale?
May I ask a side question: since we all do what you do all the time but not exactly your workflow, is this system a companywide methodology, a client required methodology, or just somethin you fell into over the years?
Annotative text/dimensions/blocks (and the added benefit of using layouts and viewports) have literally done away with your workflow for many of us over the last 20-ish years now.
A quick lisp lesson, you can make little functions like set dimstyle. You can save these say in a lisp along with other helper functions, then use appload yourlisp and add to the start up suite then it gets loaded every time you start Cad.
(defun c:d5 ( ) (command "._-dimstyle" "_restore" "Dimstyle 5")(setvar 'clayer "DIM5"))
(defun c:d6 ( ) (command "._-dimstyle" "_restore" "Dimstyle 6")(setvar 'clayer "DIM6"))
(defun c:d7 ( ) (command "._-dimstyle" "_restore" "Dimstyle 7")(setvar 'clayer "DIM7"))
So as above type D6 and correct dimstyle is set and layer.
Hope it makes sense. Yes it is simple and has no error checking about stuff missing.
Hello pendean,
To clarify, I'll describe "our" way of working, perhaps you can advise on the "right way to do things." I work in a mid-sized metal construction company; I was in the workshops and was offered to move to the technical offices. We mainly make doors, windows, barriers, frames, and other traditional metal jobs. It's been 6 months since I started drawing on AutoCad.
We all share the same layers, the same Dimstyles, so we can easily continue someone else's work, at least in theory. Some don't use layers at all and just change colors while keeping the same layer, for example. Ultimately, everyone does a bit as they please. There's no real methodology to follow, and I learn by experimenting. The only thing is not to use annotative because most colleagues don't understand how to use it.
Regarding my workflow:
When I want to put dimensions at scale, I select my Dimstyle, draw , assign it the desired scale layer, and make it current if I need to continue. The same for arrows. In general, I assign the layer scale to dimensions and arrows.
For text, I manually change the font size according to the scale.
Hoping this helps you see the situation, if you have any "veteran" advice, I gladly welcome it 😄
@Sea-Haven Hello 😮 ,
I've tried your code, and it works perfectly, which also helped me understand AutoLISP a bit better. Unfortunately, it's not exactly what I was looking for. After some research, it seems that what I want might be a bit too complex for me at the moment. Ideally, I'd like AutoCAD to automatically recognize when I use a dimension, check the current dimstyle, set the layer of the new object automatically to one I've chosen, and then revert to my previous layer before I drew the dimension.
For now, I've found a simpler solution: setting up palettes and using them. There, I can set up both the dimstyle and the layer. It requires a few more clicks, but it's good enough for now.
hey there,
check this one. fill in your style-layer associations starting line 13, save, load both and start command-adding dimensions.
;****************************************************************************************************************
(if (/= 'vlr-command-reactor (type command_ended_reactor))
(setq command_ended_reactor (vlr-command-reactor nil '((:vlr-commandended . command_ended))))
)
;****************************************************************************************************************
(defun command_ended (reactor_object parameter_list / dim_style_layer_assoc_list is_dim dim_dxf style_layer_pair)
(setq dim_style_layer_assoc_list '(
; dim_style corresponding_layer
("COTE5" . "COT_DET_5")
; ...
)
)
(if (and
(setq is_dim (wcmatch (cdr (assoc 0 (setq dim_dxf (entget (entlast))))) "*DIMENSION*"))
(setq style_layer_pair (assoc (cdr (assoc 3 dim_dxf)) dim_style_layer_assoc_list))
)
(entmod (subst (cons 8 (cdr style_layer_pair)) (assoc 8 dim_dxf) dim_dxf))
(if is_dim (alert (strcat "Paired layer for \"" (cdr (assoc 3 dim_dxf)) "\"dimstyle not set")))
)
)
;****************************************************************************************************************
updated
@komondormrex Wow! Really?? I would not expect something so bad from you.
I can imagine that something easy like this could serve the purpose.
(defun c:Load_DimStyleReactor nil (if *Reactor-DimStyle* (vlr-remove *Reactor-DimStyle*)) (setq *Reactor-DimStyle* (vlr-sysvar-reactor nil '((:vlr-sysVarChanged . DimStyle-CallBack))))) (defun c:Unload_DimStyleReactor nil (if *Reactor-DimStyle* (vlr-remove *Reactor-DimStyle*)) (princ)) (defun DimStyle-CallBack (rea lst / new) (and (= (car lst) "DIMSTYLE") (setq new (cond ((cdr (assoc (getvar 'dimstyle) '(("COTE1" . "JX_Cotdet_1_1") ("COTE5" . "JX_Cotdet_1_5") )))) ("JX_Cotdet"))) ; name if style not match (/= (getvar 'dimlayer) new) (setvar 'dimlayer new))) (c:Load_DimStyleReactor) ; AUTOLOAD
@ВeekeeCZ wrote:@komondormrex Wow! Really?? I would not expect something so bad from you.
what are you talking about?
Can't find what you're looking for? Ask the community or share your knowledge.