RLispLearner Posted April 29, 2023 Posted April 29, 2023 Hello all, I am trying to change the properties of a selected existing dimension. I can use "chprop" to change some but not able to change other variables. I am trying to re-select the dimension of what I just updated (after using "chprop") and change the rest of the properties by updating the variables. I don't think I am "re-selecting" it correctly because it doesn't seem to change (or I'm just not doing it right) Doesn't update: "DIMLUNIT" "4" "DIMTXT" "24" "DIMTFILL" "1" "DIMLTYPE" "dashed" "DIMLTEX1" "dashed" "DIMLTEX2" "dashed" Here is my code so far: ; Select any existing dimension and update its properties (DEFUN C:changeDIM () ;save variable (setq oldltscale (getvar "ltscale")) ; Load the linetype "dashed" (command "linetype" "load" "dashed" "acadiso.lin" "") ;Select an existing dimension to update (princ "select objects\n") (setq NewDimSettings (ssget)) ;Change the properties of the selected dimension (color, linetype, linetype, scale) (command "chprop" NewDimSettings "" "COLOR" "yellow" "LTYPE" "dashed" "LTscale" "20" "") ;Select the dim that was just updated to continue updating more variables (setq NewDimSettings2 (ssget "_p")); Doesn't seem to work ;(ssget "NewDimSettings"); Doesn't seem to work ;With previously updated dim now selected again, update other variables (command "DIMLUNIT" "4" "DIMTXT" "24" "DIMTFILL" "1" "DIMLTYPE" "dashed" "DIMLTEX1" "dashed" "DIMLTEX2" "dashed" "") (command "regen") ;reset variable (setvar "ltscale" oldltscale) (princ) );end Attached image: Highlighted are some of the Dim properties I am trying to update after it is selected... Thanks in advance for any assistance! Quote
BIGAL Posted April 30, 2023 Posted April 30, 2023 (edited) Using lisp you can change variables, for a selected object, so the (command "DIMLUNIT" .... has no effect on what you have selected. Often with dims though need to reset more than 1 variable. Use dumpit.lsp to look at properties you can change them. For a ssget you need to loop through the selection set and use (ssname ssdim x) x is the selection set item number starts at 0. I would also add a filter to your ssget (setq ssdim (ssget '((0 . "DIMENSION") ))) ;;;===================================================================; ;;; DumpIt ; ;;;-------------------------------------------------------------------; ;;; Dump all methods and properties for selected objects ; ;;;===================================================================; (defun C:Dumpit ( / ent) (while (setq ent (entsel)) (vlax-Dump-Object (vlax-Ename->Vla-Object (car ent)) ) ) (princ) ) ;(dumpallproperties (car (entsel))) example of a change a dim (vla-put-arrowheadsize dimobj 5) Do you know how to loop through a selection set ? Edited April 30, 2023 by BIGAL 1 Quote
RLispLearner Posted May 1, 2023 Author Posted May 1, 2023 Thanks Big Al. You are always one of the first to help! I wanted to get a little more educated on your suggestion before asking questions so have been trying to do some homework on my end first. While I was looking up info, I came across some code that seems to do the job. I modified it to what I needed, and for the most part, it works. Code: (DEFUN C:changedim (/ getthedim ent dimobject) (vl-load-com) ;save variable (setq oldltscale (getvar "ltscale")) ; Load the linetype "dashed" (command "linetype" "load" "dashed" "acadiso.lin" "") (if (setq getthedim (ssget "_:L" '((0 . "*DIMENSION")))) (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex getthedim))) (setq dimobject (vlax-ename->vla-object ent)) (vla-put-UnitsFormat dimobject 4) (vla-put-ExtensionLineColor dimobject 2) (vla-put-DimensionLineColor dimobject 2) (vla-put-Arrowhead1Type dimobject 0) (vla-put-Arrowhead2Type dimobject 0) (vla-put-arrowheadsize dimobject 12) (vla-put-textheight dimobject 12) (vla-put-textcolor dimobject 2) (vla-put-PrimaryUnitsPrecision dimobject 0) (VLA-PUT-Linetype dimobject "dashed") (VLA-PUT-LinetypeScale dimobject 2) (VLA-PUT-DIMENSIONLINETYPE dimobject "dashed") (VLA-PUT-EXTLINE1LINETYPE dimobject "dashed") (VLA-PUT-EXTLINE2LINETYPE dimobject "dashed") ;Next, change the fill color to background ;(vla-put-textfillcolor dimobject 1);not working ;(vla-put-backgroundcolor dimobject 1);not working ;(vla-put-backgroundfill dimobject 1);not working ;(vla-put-textbackgroundfill dimobject 1);not working ) ) (command "regen") ;reset variable (setvar "ltscale" oldltscale) (princ) );END Everything seems to work except change fill color to “background” (as seen below) Ive tried these functions but none work: vla-put-backgroundcolor vla-put-backgroundfill vla-put-textbackgroundfill vla-put-textfillcolor Do you know what the correct function is by chance? Thanks again! Quote
hosneyalaa Posted May 1, 2023 Posted May 1, 2023 hi try (vla-put-textfillcolor dimobject 1) (vla-put-textfill dimobject :vlax-true) Quote
RLispLearner Posted May 2, 2023 Author Posted May 2, 2023 Thanks for the response. Your code does change the color for me. Thanks! Do you know the number that changes it to “background” by chance? That’s what I’m hoping to find. I looked around and couldn’t find any code that would change the Fill color to "Background" by using a specific number. I did find some code that does change the fill color to "Background", but it’s not straight forward as just using the correct number. It does seem to work though. The code is: (defun c:bms ( / ent1 exdata newent) (setq ent1 (entget (car (entsel "\nselect dimension:")))) (setq exdata '((-3 ("ACAD" (1000 . "DSTYLE") (1002 . "{") (1070 . 69) (1070 . 1) (1002 . "}"))))) (setq newent (append ent1 exdata)) (entmod newent) (princ)) Credit:https://forums.augi.com/showthread.php?96293-Dimension-background-mask-in-AutoCAD-2009 So what I’ve been trying to do is to incorporate this working code (for background) into what I already have (that changes everything else I need). I am not having success merging the two together unfortunately. Getting a Syntax error. What I’ve tried. (defun c:changedim ( / ent1 ent2 exdata newent) (vl-load-com) ;save variable (setq oldltscale (getvar "ltscale")) ; Load the linetype "dashed" (command "linetype" "load" "dashed" "acadiso.lin" "") (setq ent1 (entget (car (entsel "\nselect dimension:")))) (setq exdata '((-3 ("ACAD" (1000 . "DSTYLE") (1002 . "{") (1070 . 69) (1070 . 1) (1002 . "}"))))) (setq newent (append ent1 exdata)) (entmod newent) (if (setq ent2 ent1)) (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ent2))) (vla-put-UnitsFormat ent2 4) (vla-put-ExtensionLineColor ent2 2) (vla-put-DimensionLineColor ent2 2) (vla-put-Arrowhead1Type ent2 0) (vla-put-Arrowhead2Type ent2 0) (vla-put-arrowheadsize ent2 12) (vla-put-textheight ent2 12) (vla-put-textcolor ent2 2) (vla-put-PrimaryUnitsPrecision ent2 0) (VLA-PUT-Linetype ent2 "dashed") (VLA-PUT-LinetypeScale ent2 2) (VLA-PUT-DIMENSIONLINETYPE ent2 "dashed") (VLA-PUT-EXTLINE1LINETYPE ent2 "dashed") (VLA-PUT-EXTLINE2LINETYPE ent2 "dashed") ) (command "regen") ;reset variable (setvar "ltscale" oldltscale) (princ) ) My IF statement is not working now that I’ve altered it. Maybe someone can spot the issue and help me merge the two together. Thanks in Advance! Quote
BIGAL Posted May 2, 2023 Posted May 2, 2023 (edited) Try this, you need a VL object in most cases to use VL commands. (defun c:changedim ( / ent1 ent2 exdata newent oldsltscale exdata newent) (vl-load-com) (setq oldltscale (getvar "ltscale")) (setq ent (car (entsel "\nselect dimension:"))) (setq ent1 (entget ent)) (setq exdata '((-3 ("ACAD" (1000 . "DSTYLE") (1002 . "{") (1070 . 69) (1070 . 1) (1002 . "}"))))) (setq newent (append ent1 exdata)) (entmod newent) (setq ent2 (vlax-ename->vla-object ent)) (vla-put-UnitsFormat ent2 4) (vla-put-ExtensionLineColor ent2 2) (vla-put-DimensionLineColor ent2 2) (vla-put-Arrowhead1Type ent2 0) (vla-put-Arrowhead2Type ent2 0) (vla-put-arrowheadsize ent2 12) (vla-put-textheight ent2 12) (vla-put-textcolor ent2 2) (vla-put-PrimaryUnitsPrecision ent2 0) (VLA-PUT-Linetype ent2 "dashed") (VLA-PUT-LinetypeScale ent2 2) (VLA-PUT-DIMENSIONLINETYPE ent2 "dashed") (VLA-PUT-EXTLINE1LINETYPE ent2 "dashed") (VLA-PUT-EXTLINE2LINETYPE ent2 "dashed") (command "regen") (setvar "ltscale" oldltscale) (princ) ) Edited May 2, 2023 by BIGAL Quote
RLispLearner Posted May 4, 2023 Author Posted May 4, 2023 Yes. That seemed to do the trick. Looks like the original IF statement wasn't even needed to work then. Its still curious what code it took to change the Text Fill to "Background". I was thinking I just had to find the correct number (Like osmode "16383"). Perhaps there is a number, but I never came across it in my search... Thanks again BigAl! You are always helpful... Quote
tombu Posted May 4, 2023 Posted May 4, 2023 18 hours ago, RLispLearner said: Yes. That seemed to do the trick. Looks like the original IF statement wasn't even needed to work then. Its still curious what code it took to change the Text Fill to "Background". I was thinking I just had to find the correct number (Like osmode "16383"). Perhaps there is a number, but I never came across it in my search... Thanks again BigAl! You are always helpful... The (setq exdata '((-3 ("ACAD" (1000 . "DSTYLE") (1002 . "{") (1070 . 69) (1070 . 1) (1002 . "}"))))) (setq newent (append ent1 exdata)) (entmod newent) part. Quote
RLispLearner Posted May 14, 2023 Author Posted May 14, 2023 Sorry. I meant to say: Does any one know why it take such elaborate code just to change the text fill to "Background"? The other values are changed by just setting a variable to something simple (like a number). Example: (vla-put-textcolor ent2 2) Wonder why its just not as simple as changing the textfill value with a number as well: (vla-put-textfill ent2 2) or perhaps (vla-put-backgroundfill ent2 2) No biggy. Just curious if anyone knew. Seems like allot of code to change that value. 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.