3dwannab Posted July 23, 2018 Posted July 23, 2018 See attached a jpeg of the problem of the attached dwg file for testing. When I use my code below for setting the dim text locations back to default it has no effect. PS. These dims have no style overrides. (defun c:Dim_Text_Reset (/ ss) (if (setq ss (ssget '((0 . "DIMENSION")))) (progn (command "_dim1" "HOME" ss "") (princ (strcat "\nAll selected dimension text has been reset on < " (itoa (sslength ss)) " > object/s")) ) (princ "\n*** Nothing Selected ***") ) (setq ss nil) (princ) ) Another Q is in there and not so LISP related but if anyone can answer that, that would be great. CAD FILE: Dim Forum Q.dwg IMAGE: Quote
tombu Posted July 23, 2018 Posted July 23, 2018 #1 They are in the home position. If you move them you can set them back to the default home position. #2 That's default behavior, if you move the object all the dimensions move with it. It can be lined back up easily enough. Quote
3dwannab Posted July 23, 2018 Author Posted July 23, 2018 #1 They are in the home position. If you move them you can set them back to the default home position.#2 That's default behavior, if you move the object all the dimensions move with it. It can be lined back up easily enough. 1. The top left dim is not at it's home position. When you open the file and run the lisp it works. But the right one does not. 2. OK, pity. I'd rather the node to move. Oh well. Thanks. Quote
3dwannab Posted July 24, 2018 Author Posted July 24, 2018 (edited) FIXED. A hacky way of doing it but Hey-ho. ED. Sorry I accidentally edited my post instead of a new one. It's 1:30am. Those attachments are just the vla and dxf outputs of the 2 dims. I'll leave them there if anyone can spot what was actually wrong. Just use MS Word to comapare the two. ;; 1.0 - Initial release. ;; 1.1 - Add nothing selected and selection input for user. ;; 1.2 - Fixed ACAD bug where the text doesn't want to reset position after the DIMSPACE command. ;; by 3dwannab ;;--------------------------------------------------------------;; (defun c:Dim_Text_Reset (/ ss_1 dObj len ) (if (setq ss_1 (ssget '((0 . "DIMENSION")))) (progn (vlax-for dObj (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))) ;; These just mess around with the default which will mean it'll work for all dim style variants. (vla-put-TextMovement dObj 0) (vla-put-TextMovement dObj 1) (vla-put-TextMovement dObj 2) (vla-put-TextMovement dObj 3) ) ;; Regular old command to then set the dim text position to home. (command "_dim1" "HOME" ss_1 "") (princ (strcat "\n >>> " (itoa (setq len (sslength ss_1))) (if (> len 1) " text positions on selected dimensions have been reset" " text position on selected dimension has been reset") " <<< \n")) ) (princ "\n*** Nothing Selected ***\n") ) (setq ss_1 nil) (princ) )(princ) (princ "\n3dwannab_Dim_Text_Reset.lsp | Version 1.2 | by 3dwannab\n") (princ "\nType \"Dim_Text_Reset\" to Invoke\n") (princ) Dim Good.docx Dim Bad.docx Edited July 25, 2018 by 3dwannab Tired. Quote
3dwannab Posted July 25, 2018 Author Posted July 25, 2018 Another thing, I've added a dimspace to '0' function seeing as it now no longer messes anything up. ;; 1.0 - Initial release. ;; 1.1 - Add nothing selected and selection input for user. ;; 1.2 - Fixed ACAD bug where the text doesn't want to reset position after the DIMSPACE command. ;; 1.3 - Added a DIMSPACE to '0' function. ;; by 3dwannab ;;--------------------------------------------------------------;; (defun c:DTR nil (c:Dim_Text_Reset)) (defun c:Dim_Text_Reset (/ cmde dObj ent_1 ent_1_data len os ss_1 ) ;; START ERROR CHECK (defun *error* (errmsg) (and acDoc (vla-EndUndoMark acDoc)) (and errmsg (not (wcmatch (strcase errmsg) "*CANCEL*,*EXIT*")) (princ (strcat "\n<< Error: " errmsg " >>\n")) ) (setvar 'cmdecho cmde) (setvar 'osmode os) ) (setq acDoc (vla-get-ActiveDocument (vlax-get-acad-object))) (or (vla-EndUndoMark acDoc) (vla-StartUndoMark acDoc)) (setq cmde (getvar "cmdecho")) (setq os (getvar "osmode")) (setvar 'cmdecho 0) (setvar 'osmode 0) ;; START MAIN FUNCTION ;; initget from LeeMac help pages (initget "Yes No") (setq ans (cond ( (getkword (strcat "\nDIMPACE TO 0 ?\n:---------------------------------------------------------:\nWill reset the dimensions with a DIMSPACE value of '0'.\n:---------------------------------------------------------:\n [Yes/No] <" (setq ans (cond ( ans ) ( "Yes" )) ) ">: " ) ) ) ( ans ) ) ) (cond ((= "Yes" ans) (while (not (and (setq ent_1 (car (entsel "\nPlease select a DIMENSION as a base point\n:---------------------------------------------------------:\n")) ent_1_data (if ent_1 (entget ent_1)) ) (= (cdr (assoc 0 ent_1_data)) "DIMENSION") (progn (if (setq ss_1 (ssget '((0 . "DIMENSION")))) (progn (command "._dimspace" "_non" ent_1 "_non" ss_1 "" "0") (princ (strcat "\n >>> " (itoa (setq len (sslength ss_1))) (if (> len 1) " dimensions have been 0'd" " dimension has been 0'd") " <<< \n"))(princ) ) (progn (princ "\n*** Nothing Selected ***\n")(princ) ) ) ) ) ) ) ) ((= "No" ans) (princ (strcat "\n >>> DIMSPACE to '0' not performed. <<< \n"))(princ) ) ) (setq ss_1 nil) (princ "\n:---------------------------------------------------------:\nSelect Dims to have their TEXT reset.\n:---------------------------------------------------------:\n") (if (setq ss_1 (ssget '((0 . "DIMENSION")))) (progn (vlax-for dObj (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))) ;; These just mess around with the default which will mean it'll work for all dim style variants. (vla-put-TextMovement dObj 0) (vla-put-TextMovement dObj 1) (vla-put-TextMovement dObj 2) (vla-put-TextMovement dObj 3) ) ;; Regular old command to then set the dim text position to home. (command "_dim1" "HOME" ss_1 "") (princ (strcat "\n >>> " (itoa (setq len (sslength ss_1))) (if (> len 1) " text positions on selected dimensions have been reset" " text position on selected dimension has been reset") " <<< \n")) ) (princ "\n*** Nothing Selected ***\n") ) (*error* nil) (setq ss_1 nil) (setq ent_1 nil) (setq ent_1_data nil) (princ) ;; END MAIN FUNCTION ) (princ "\n3dwannab_Dim_Text_Reset.lsp | Version 1.3 | by 3dwannab\n") (princ "\nType \"Dim_Text_Reset\" OR \"DTR\" to Invoke\n")(princ) Quote
Roy_043 Posted July 26, 2018 Posted July 26, 2018 @3dwannab: Your code doesn't work properly in BricsCAD. The TextMovement property cannot have a value of 3. I am surprised AutoCAD accepts this. Also: changing this property results in an additional override (just check the Xdata). And that is perhaps not your intention. Quote
3dwannab Posted July 26, 2018 Author Posted July 26, 2018 Does it work with 0 to 2? I'm not adept at working with Xdata ATM. vla-methods are a lot easier for me to understand. Quote
Roy_043 Posted July 27, 2018 Posted July 27, 2018 @3dwannab: Yes, value 0-2 are accepted. I am stumped by this as well (BTW: BricsCAD doen't have a _DimSpace command), and kudo's to you for finding a solution. There must be some property controlling this that is not exposed to (Visual) Lisp. But since the code adds an override for the TextMovement property it may be better to get the value from the dimstyle: (defun c:Dim_Text_Reset (/ len ss ssAct) (if (setq ss (ssget '((0 . "DIMENSION")))) (vlax-for dObj (setq ssAct (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)))) (vla-put-textmovement dObj ;; Grap the DIMTMOVE (=TextMovement) from the dimstyle: (cdr (assoc 279 (entget (tblobjname "dimstyle" (vla-get-stylename dObj))))) ) ;; Regular old command to then set the dim text position to home. (command "_dim1" "HOME" ss "") (princ (strcat "\n >>> " (itoa (setq len (sslength ss))) (if (> len 1) " text positions on selected dimensions have been reset" " text position on selected dimension has been reset") " <<< \n")) (vla-delete ssAct) ) (princ "\n*** Nothing Selected ***\n") ) (princ) ) To check the Xdata use (entget (car (entsel)) '("*")): ( ... (5 . "E00") ... ( -3 ( "AcadAnnotative" (1000 . "AnnotativeData") (1002 . "{") (1070 . 1) (1070 . 1) (1002 . "}") ) ( "ACAD_DIMASSOC_CALC_DIMLFAC" (1040 . -9.99999800950551) ) ( "ACAD_DIMASSOC_DIMLFAC" (1040 . -9.99999800950551) ) ( "ACAD_DIMASSOC_OVERRIDDEN_DIMLFAC" (1040 . 0.0) ) ( "ACAD" (1000 . "DSTYLE") (1002 . "{") (1070 . 279) ; Extra override 297=DIMTMOVE. (1070 . 1) ; Extra override value. (1070 . 40) (1040 . 1.0) (1070 . 144) (1040 . -9.99999800950551) (1002 . "}") ) ) ) Quote
3dwannab Posted July 27, 2018 Author Posted July 27, 2018 Thanks, it was really bugging me as I have to dim a lot of small measurements and having the dim text lined up with the dim line wasn't on, so I had to come up with a solution. Prob a little more brute force than your way but I was glad to find one. Thanks for those code snippets. Will come in handy in the future. Quote
3dwannab Posted August 5, 2018 Author Posted August 5, 2018 I've updated the script to now select the first row of DIM with a DIMSPACE value of 0. The for any subsequent rows it adds a value of 10. But as you can see the first row gets messed up after selecting the 2nd row in the GIF. The 2nd row of dims are not spaced the same either. I really thought I had created a good script until, I spotted this. I tried setting ss_1 variable to nil but no luck. It still messes with the 1st row. LATEST CODE: ;; 1.0 - Initial release. ;; 1.1 - Add nothing selected and selection input for user. ;; 1.2 - Fixed ACAD bug where the text doesn't want to reset position after the DIMSPACE command. ;; 1.3 - Added a DIMSPACE to '0' function. ;; 1.4 - Removed the options. To tedious to run the command ;; Instead you run the command and do the first row of DIMENSIONS with a spacing of '0'. ;; Then the LISP will add a spacing value to the next row of dimensions. (see set_dim_space in the DIMENSION spacing options below).Change to your requirements. ;; by 3dwannab Latest rev - 05-08-2018 ;;--------------------------------------------------------------;; (defun c:---Dim_Text_Align_Reset (/) (LOAD "3dwannab_Dim_Text_Align_Reset") (c:DTAR)) (defun c:DTAR nil (c:Dim_Text_Align_Reset)) (defun c:Dim_Text_Align_Reset (/ cnt dObj ent_1 ent_1_data len set_dim_space ss_1 ssAct var_cmdecho var_osmode ) ;;--------------------------------------------------------------;; ; OPTIONS - DIMENSION spacing. ;;--------------------------------------------------------------;; (setq set_dim_space 10) ;;--------------------------------------------------------------;; ;; START ERROR CHECK (defun *error* (errmsg) (and acDoc (vla-EndUndoMark acDoc)) (and errmsg (not (wcmatch (strcase errmsg) "*CANCEL*,*EXIT*")) (princ (strcat "\n<< Error: " errmsg " >>\n")) ) (setvar 'cmdecho var_cmdecho) (setvar 'osmode var_osmode) ) (setq acDoc (vla-get-ActiveDocument (vlax-get-acad-object))) (or (vla-EndUndoMark acDoc) (vla-StartUndoMark acDoc)) (setq var_cmdecho (getvar "cmdecho")) (setq var_osmode (getvar "osmode")) (setvar 'cmdecho 0) (setvar 'osmode 0) (setq cnt 0) (while (not (and (setq ent_1 (car (entsel (strcat "\n: -------------------------\nSelect base DIM, then 1st row of DIMs'. 2nd, 3rd etc. will be + '" (itoa set_dim_space) "' spacing each time.\n: -------------------------\n"))) ent_1_data (if ent_1 (entget ent_1)) ) (= (cdr (assoc 0 ent_1_data)) "DIMENSION") (while (if (= 0 cnt) (setq ss_1 (LM:ssget "\nSelect your first row of DIMENSIONS to align:\n" (list "_:L" (append '((0 . "DIMENSION")))))) (setq ss_1 (LM:ssget "\nSelect your next row of DIMENSIONS to align:\n" (list "_:L" (append '((0 . "DIMENSION")))))) ) (progn (if (= 0 cnt) (command "._dimspace" "_non" ent_1 "_non" ss_1 "" 0) ) (if (< 0 cnt) (command "._dimspace" "_non" ent_1 "_non" ss_1 "" (* cnt set_dim_space)) ) (princ (strcat "\n: -------------------------\n" (itoa (setq len (sslength ss_1))) (if (> len 1) " DIMS have been " " DIMS has been ") "DIMSPACE'd with a value of '" (itoa (* cnt set_dim_space)) "'"))(princ) (setq cnt (1+ cnt)) (if ss_1 (progn (vlax-for dObj (setq ssAct (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)))) ;; These just mess around with the default which will mean it'll work for all dim style variants. (vla-put-TextMovement dObj 0) (vla-put-TextMovement dObj 1) (vla-put-TextMovement dObj 2) (vla-put-TextMovement dObj 3) ) ;; Regular old command to then set the dim text position to home. (command "._dimedit" "HOME" ss_1 "") (princ (strcat " + '" (itoa (setq len (sslength ss_1))) (if (> len 1) "' text positions on dimensions have been reset." " text position on dimension has been reset.")"\n: -------------------------\n")) (vla-delete ssAct) ;; PROBLEM ;; See here, by setting the ss_1 to nil, would that not fix the problem? (setq ss_1 nil) ) (princ "\n: -------------------------\n*** Nothing Selected ***\n: -------------------------\n") ) ) ) ) ) ) (*error* nil) (setq set_dim_space 0) (setq ent_1 nil) (setq ent_1_data nil) (setq ss_1 nil) (princ) ) ;; END MAIN FUNCTION (princ "\n3dwannab_Dim_Text_Align_Reset.lsp | Version 1.4 | by 3dwannab\n") (princ "\nType \"Dim_Text_Align_Reset\" OR \"DTAR\" to Invoke\n")(princ) ;; -------------------------- START SUB-ROUTINES -------------------------- ;; ;; ssget - Lee Mac ;; A wrapper for the ssget function to permit the use of a custom selection prompt ;; ;; Arguments: ;; msg - selection prompt ;; params - list of ssget arguments (defun LM:ssget ( msg params / sel ) (princ msg) (setvar 'nomutt 1) (setq sel (vl-catch-all-apply 'ssget params)) (setvar 'nomutt 0) (if (not (vl-catch-all-error-p sel)) sel) ) 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.