AeJay Posted April 13, 2023 Share Posted April 13, 2023 (edited) Currently there is this code here the forums: (defun c:DLA ( / sel ent txp al ar mp uALR s txpp uvt tp exss exssent exssl exssindex) (defun deg2rad (ang / ) (/ (* PI ang) 180.0) ) (defun rad2deg ( ang / ) (/ (* 180.0 ang) PI) ) ;; midpoint of 2 given points (defun mid ( pt1 pt2 / ) (mapcar '(lambda (x y) (+ (* 0.5 x) (* 0.5 y))) pt1 pt2 ) ) ;;; Calculate unit vector of vector a (defun uvec (a / d) (setq d (distance '(0 0 0) a) a (mapcar '/ a (list d d d)) ) ) ; Compute the dot product of 2 vectors a and b (defun dot ( a b / dd) (setq dd (mapcar '* a b)) (setq dd (+ (nth 0 dd) (nth 1 dd) (nth 2 dd))) ) ;end of dot (princ "\nInput Desired Distance: ") (setq dist (getreal)) (princ "\nSelect Dimension(s) To Change: ") (setq exss (ssget '((0 . "*dim*")))) (setq exssl (sslength exss)) (setq exssindex 0) (repeat exssl (setq exssent (entget (ssname exss exssindex))) (setq ent (cdr (car exssent))) (setq txp (cdr (assoc 10 (entget ent)))) (setq al (cdr (assoc 13 (entget ent)))) (setq ar (cdr (assoc 14 (entget ent)))) (setq mp (mapcar '/ (mapcar '+ al ar) '(2. 2. 2.) ) ) ; uALR = unit vector from al to ar (setq uALR (uvec (mapcar '- ar al))) (setq s (dot uALR (mapcar '- txp al))) ; txpp = projection of txp onto the line (setq txpp (mapcar '+ al (mapcar '* uALR (list s s s))) ) (setq uvt (uvec (mapcar '- txp txpp))) (setq tp (mapcar '+ mp (mapcar '* uvt (list dist dist dist)))) (entmod (subst (cons 10 tp) (assoc 10 (entget ent)) (entget ent)) ) (entmod (subst (cons 11 tp) (assoc 11 (entget ent)) (entget ent)) ) (setq exssindex (+ exssindex 1)) ) (princ) ) But the thing is it calculates the distance only to objects the dim lines are directly attached to. I wanted it to somehow base the distance for things such as holes inside an object to 200mm away (in a 1:10 scale) from the object than the 200m away from the hole directly. Somehow making the intersection of the dim line and the object to be basis for objects that are inside the object. Edited April 13, 2023 by AeJay Quote Link to comment Share on other sites More sharing options...
mhupp Posted April 13, 2023 Share Posted April 13, 2023 Going to need a sample drawing to understand what your talking about. ;; midpoint of 2 given points (defun mid (p1 p2 / ) (mapcar '/ (mapcar '+ p1 p2) '(2 2 2)) ) Quote Link to comment Share on other sites More sharing options...
AeJay Posted April 13, 2023 Author Share Posted April 13, 2023 29 minutes ago, mhupp said: Going to need a sample drawing to understand what your talking about. ;; midpoint of 2 given points (defun mid (p1 p2 / ) (mapcar '/ (mapcar '+ p1 p2) '(2 2 2)) ) Attached is my sample drawing. You can try and use DLA function for it. It will work for the 200mm and 592mm measured dim line, but for the others it will mess up the calculation. I somehow wanted it to calculate the dim line that is attached or intersecting the object rather than the hole instead, which will make the intersecting point as the basis of the dim line distance for objects that have either the left or right dim line connected inside the object. testDWG.dwg Quote Link to comment Share on other sites More sharing options...
AeJay Posted April 14, 2023 Author Share Posted April 14, 2023 I currently have this code for dim line adjustment, however, whenever I select any dimension line in the sample drawing. It says that it is is an invalid dimension line. (defun c:testDLTool (/ dim-line offset factor new-offset new-length new-text) (setq dim-line (car (nentsel "\nSelect dimension line: "))) (if (= (type dim-line) 'ENAME) (progn (setq offset 200.0) (setq factor 10.0) (setq new-offset (/ offset factor)) (setq length-data (assoc 42 (entget dim-line))) (if length-data (progn (setq new-length (+ (cdr length-data) new-offset)) (setq new-text (rtos (* new-length factor) 2 2)) (entmod (subst (cons 42 new-length) length-data (entget dim-line))) (entmod (subst (cons 1 new-text) (assoc 1 (entget dim-line)) (entget dim-line))) (princ "\nDimension line adjusted successfully.") ) (princ "\nSelected object is not a dimension line.") ) ) (princ "\nInvalid selection.") ) (princ) ) testDWG.dwg Quote Link to comment Share on other sites More sharing options...
BIGAL Posted April 14, 2023 Share Posted April 14, 2023 (edited) I would look for LINE (if (= (cdr (assoc 0 (entget dim-line))) "LINE") also (setq length-data (cdr (assoc 42 (entget dim-line)))) also (setq entg (entget dim-line)) save repeating in code Edited April 14, 2023 by BIGAL Quote Link to comment Share on other sites More sharing options...
BIGAL Posted April 14, 2023 Share Posted April 14, 2023 (edited) Ok simplest way is dont add holes then dim, rather add holes via a offset from edges and then the dim will follow. Have something somewhere. Above image pick vertical, then questions 2, 65 70, 117, 200,50 Just have to check which one matches your request. Happy to provide some code but need how you see the sequence of entering data. Edited April 14, 2023 by BIGAL 1 Quote Link to comment Share on other sites More sharing options...
AeJay Posted April 14, 2023 Author Share Posted April 14, 2023 16 minutes ago, BIGAL said: I would look for LINE (if (= (cdr (assoc 0 (entget dim-line))) "LINE") also (setq length-data (cdr (assoc 42 (entget dim-line)))) also (setq entg (entget dim-line)) save repeating in code Tried this, but still says that "Selected object is not a dimension line"" (defun c:test (/ dim-line offset factor new-offset new-length new-text) (setq dim-line (car (nentsel "\nSelect dimension line: "))) (if (= (cdr (assoc 0 (entget dim-line))) "LINE") (progn (setq offset 200.0) (setq factor 10.0) (setq new-offset (/ offset factor)) (setq length-data (cdr (assoc 42 (entget dim-line)))) (if length-data (progn (setq new-length (+ (cdr length-data) new-offset)) (setq new-text (rtos (* new-length factor) 2 2)) (entmod (subst (cons 42 new-length) length-data (entget dim-line))) (entmod (subst (cons 1 new-text) (assoc 1 (entget dim-line)) (entget dim-line))) (princ "\nDimension line adjusted successfully.") ) (princ "\nSelected object is not a dimension line.") ) ) (princ "\nInvalid selection.") ) (princ) ) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted April 14, 2023 Share Posted April 14, 2023 (edited) Works for me (setq dim-line (car (nentsel "\nSelect dimension line: "))) Select dimension line: <Entity name: 3d917760> : (= (cdr (assoc 0 (entget dim-line))) "LINE") T Are you sure its a dim or at least a LINE ? Copy this to command line and look at (0 . "LINE") means a line. (entget (car (nentsel "\nPick dim line "))) Edited April 14, 2023 by BIGAL Quote Link to comment Share on other sites More sharing options...
AeJay Posted April 14, 2023 Author Share Posted April 14, 2023 (edited) 24 minutes ago, BIGAL said: Works for me (setq dim-line (car (nentsel "\nSelect dimension line: "))) Select dimension line: <Entity name: 3d917760> : (= (cdr (assoc 0 (entget dim-line))) "LINE") T Are you sure its a dim or at least a LINE ? Copy this to command line and look at (0 . "LINE") means a line. (entget (car (nentsel "\nPick dim line "))) Yes, it is (0 . "LINE") indeed. Can you check on the last code I sent please? Not sure why it still does not consider it a line Edited April 14, 2023 by AeJay Quote Link to comment Share on other sites More sharing options...
AeJay Posted April 14, 2023 Author Share Posted April 14, 2023 20 minutes ago, BIGAL said: Ok simplest way is dont add holes then dim, rather add holes via a offset from edges and then the dim will follow. Have something somewhere. Above image pick vertical, then questions 2, 65 70, 117, 200,50 Just have to check which one matches your request. Happy to provide some code but need how you see the sequence of entering data. Would it be possible if I could have those .lsp files? I would love to see how the code would appear to have an idea. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted April 15, 2023 Share Posted April 15, 2023 (edited) Just post say a dwg showing like offset 1 offset 2, radii is obvious. How you would approach an automated solution. Things like how many holes always 4 and inside a rectang ? If so easy. do they always have different end ofsets different top / bottom. Bear in mind code could draw rectang as well. Thats why need to know how many holes and the rules Have stuff like do row of holes at different spacings and dim. Will provide code if you provide some more answers. If always like image say so. Need dwg for dim style and layers. Edited April 15, 2023 by BIGAL Quote Link to comment Share on other sites More sharing options...
BIGAL Posted April 15, 2023 Share Posted April 15, 2023 (edited) To admin this appears to be part of the same question over at post. Edited April 15, 2023 by BIGAL Quote Link to comment Share on other sites More sharing options...
AeJay Posted April 17, 2023 Author Share Posted April 17, 2023 On 4/15/2023 at 10:03 AM, BIGAL said: Just post say a dwg showing like offset 1 offset 2, radii is obvious. How you would approach an automated solution. Things like how many holes always 4 and inside a rectang ? If so easy. do they always have different end ofsets different top / bottom. Bear in mind code could draw rectang as well. Thats why need to know how many holes and the rules Have stuff like do row of holes at different spacings and dim. Will provide code if you provide some more answers. If always like image say so. Need dwg for dim style and layers. Attached are some of the dwg I am working on. What I really want to achieve is create a dim line adjustment tool that can automatically adjust lines 200mm away from the object (for a keyword like d1 and d2 for 300mm etc) that can adjust if the dim line is only attached to object or inside the rectang. s1.dwg s2.dwg Quote Link to comment Share on other sites More sharing options...
SLW210 Posted April 17, 2023 Share Posted April 17, 2023 I merged your posts. Please do not create new posts for the same topic. 1 Quote Link to comment Share on other sites More sharing options...
BIGAL Posted April 18, 2023 Share Posted April 18, 2023 (edited) Had a quick look and Acad_proxy_entity is the rectang and the holes, how was that made ? Was it from a "part" in other software ? For me can make rectang Draw holes as required Do all dims All objects plain CAD objects, pline. donut, dims. Let me know if happy with this idea. Objects on correct layer etc. Would have a dcl for enter data. Are the holes different offsets / dia on left v's right. Edited April 18, 2023 by BIGAL 1 Quote Link to comment Share on other sites More sharing options...
AeJay Posted April 18, 2023 Author Share Posted April 18, 2023 15 minutes ago, BIGAL said: Had a quick look and Acad_proxy_entity is the rectang and the holes, how was that made ? Was it from a "part" in other software ? For me can make rectang Draw holes as required Do all dims All objects plain CAD objects, pline. donut, dims. Let me know if happy with this idea. Objects on correct layer etc. Would have a dcl for enter data. Are the holes different offsets / dia on left v's right. This is a great idea, please go on with it. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted April 19, 2023 Share Posted April 19, 2023 (edited) Ok little busy at moment will do just a 4 hole in a rectang for now. Found some time added dim all 4 sides you can remove or rem out the unwanted dims. ; https://www.cadtutor.net/forum/topic/77320-how-to-fix-this-code-for-dimension-adjustment-tool/ ; Rectang with 4 holes and dimensioned ; By Alan H April 2023 (defun C:4holebox ( / oldsnaplen loff roff toff boff pt1 pt2 pt3 pt4 pt5 h1 h2 h3 h4) (if (not AH:getvalsm)(load "Multi Getvals.lsp")) (setq oldsnap (getvar 'osmode)) (setvar 'osmode 0) (setvar 'clayer "PS_PLATE") (command "._-dimstyle" "_restore" "dpq_linear") (setq ans (AH:getvalsm (list "Enter Values" "Length " 5 4 "300" "Height" 5 4 "200" "Left offset" 5 4 "25" "Right offset" 5 4 "25" "Top offset" 5 4 "25" "Bottom offset" 5 4 "25" "Radius" 5 4 "10")) ) (setq len (atof (nth 0 ans)) ht (atof (nth 1 ans)) Loff (atof (nth 2 ans)) roff (atof (nth 3 ans)) toff (atof (nth 4 ans)) Boff (atof (nth 5 ans)) rad (atof (nth 6 ans)) ) (setq pt1 (getpoint "\nSelect lower left point ")) (setq pt2 (mapcar '+ pt1 (list len 0.0 0.0))) (setq pt3 (mapcar '+ pt1 (list len ht 0.0))) (setq pt4 (mapcar '+ pt1 (list 0.0 ht 0.0))) (command "rectang" pt1 pt3) ; do holes (setq h1 (mapcar '+ pt1 (list loff boff 0.0))) (command "donut" 0.01 rad h1 "") (setq h2 (mapcar '+ pt1 (list loff (- ht toff) 0.0))) (command "donut" 0.01 rad h2 "") (setq h3 (mapcar '+ pt1 (list (- len roff) boff 0.0))) (command "donut" 0.01 rad h3 "") (setq h4 (mapcar '+ pt1 (list (- len roff) (- ht toff) 0.0))) (command "donut" 0.01 rad h4 "") ; dim 4 sides (setq pt5 (mapcar '+ pt1 (list 0.0 -265 0.0))) (command "dim" "hor" pt1 pt2 pt5 "" "exit") (setq pt5 (mapcar '+ pt4 (list 0.0 265 0.0))) (command "dim" "hor" pt3 pt4 pt5 "" "exit") (setq pt5 (mapcar '+ pt4 (list -265 0.0 0.0))) (command "dim" "ver" pt1 pt4 pt5 "" "exit") (setq pt5 (mapcar '+ pt2 (list 265 0.0 0.0))) (command "dim" "ver" pt2 pt3 pt5 "" "exit") ; do 4 sides hole dims ; bot (setq pt5 (mapcar '+ pt1 (list 0.0 -150 0.0))) (command "dim" "hor" pt1 h1 pt5 "" "exit") (command "dim" "hor" h1 h3 pt5 "" "exit") (command "dim" "hor" h3 pt2 pt5 "" "exit") ; right (setq pt5 (mapcar '+ pt2 (list 150 0.0 0.0))) (command "dim" "ver" pt2 h3 pt5 "" "exit") (command "dim" "ver" h3 h4 pt5 "" "exit") (command "dim" "ver" h4 pt3 pt5 "" "exit") ; top (setq pt5 (mapcar '+ pt3 (list 0.0 150 0.0))) (command "dim" "hor" pt4 h2 pt5 "" "exit") (command "dim" "hor" h2 h4 pt5 "" "exit") (command "dim" "hor" h4 pt3 pt5 "" "exit") ; left (setq pt5 (mapcar '+ pt1 (list -150 0.0 0.0))) (command "dim" "ver" pt1 h1 pt5 "" "exit") (command "dim" "ver" h1 h2 pt5 "" "exit") (command "dim" "ver" h2 pt4 pt5 "" "exit") (setvar 'osmode oldsnap) (princ) ) You need to save the attached to a support directory so it can be auto loaded or edit code adding file location. Multi GETVALS.lsp Edited April 20, 2023 by BIGAL 1 Quote Link to comment Share on other sites More sharing options...
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.