Jump to content

Recommended Posts

Posted (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.

 

image.png

 

 

Edited by AeJay
Posted

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))
)

 

Posted
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.

image.thumb.png.0d7f207871798e4e8c62b4ce6f344e1f.png

testDWG.dwg

Posted

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

 

Posted (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 by BIGAL
Posted (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.

 

image.png.864cc9f01296428ab73cdf959c78d9e3.png

 

Happy to provide some code but need how you see the sequence of entering data.

image.png.0679e6641539fc7a597a9e0da0215190.pngimage.png.e414f24d2d6d53e3e413c51053803384.png

Edited by BIGAL
  • Thanks 1
Posted
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)
)


 

Posted (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 by BIGAL
Posted (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 by AeJay
Posted
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.

 

image.png.864cc9f01296428ab73cdf959c78d9e3.png

 

Happy to provide some code but need how you see the sequence of entering data.

image.png.0679e6641539fc7a597a9e0da0215190.pngimage.png.e414f24d2d6d53e3e413c51053803384.png

 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.

Posted (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 by BIGAL
Posted (edited)

To admin this appears to be part of the same question over at post.

 

 

 

 

Edited by BIGAL
Posted
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

Posted

I merged your posts. Please do not create new posts for the same topic.

  • Thanks 1
Posted (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 by BIGAL
  • Thanks 1
Posted
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.

Posted (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 by BIGAL
  • Thanks 1

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...