Automatic dimension

Automatic dimension

larsr2866
Enthusiast Enthusiast
29,655 Views
60 Replies
Message 1 of 61

Automatic dimension

larsr2866
Enthusiast
Enthusiast

Hello everyone,

 

I did a bit of searching on this forum for automatic dimensions. I have found some interesting tips for automatic dimensions with selecting rectangles, but i'd try something else.

 

I made a screenshot for what i want to achieve. I want to automatically create 2 dimensions between the first lines/polylines/objects/... where i am clicking in. 

 

I hope it's clear on the screenshot i took ? (the red circle is the position i click, and at that position i would have a vertical en horizontal dimension between the first lines/plines.)

 

I don't know if there are options for this?

 

Thanks in advance.

Lars

dim.jpg

 

 
 
 
 
 
0 Likes
29,656 Views
60 Replies
Replies (60)
Message 41 of 61

sajansainju73
Community Visitor
Community Visitor

Please find the attached sample drawing.

0 Likes
Message 42 of 61

Kent1Cooper
Consultant
Consultant

@sajansainju73 wrote:

Please find the attached sample drawing.


That's a different kind of Dimensioning, but in any case the same idea has come up before.  See, for example, the DPI and DPO commands in DimPoly.lsp >here<.  If you define a Dimension Style with both extension lines and both dimension lines suppressed, it can look like your image.  The distance of the text part from the Polyline can be changed [see Message 47 there].

Kent Cooper, AIA
0 Likes
Message 43 of 61

marko_ribar
Advisor
Advisor

Here is the topic you could find useful...

https://forums.augi.com/showthread.php?168619-Automatically-dimension-all-sides-and-angles-of-select... 

 

HTH.

M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 44 of 61

17ngo01ni84
Contributor
Contributor
this looks great but can it be modified to pick circle centres and not edges
0 Likes
Message 45 of 61

hak_vz
Advisor
Advisor

@17ngo01ni84 wrote:
this looks great but can it be modified to pick circle centres and not edges

It can be done, but it's completely different algorithm. Start new request (new post), attach sample drawing and give thorough explanation. You can call me to participate in finding solution. This post is already way to long.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 46 of 61

rolisonfelipe
Collaborator
Collaborator
Accepted solution

FIRST, CONGRATULATIONS ON THE EXCELLENT SOLUTION.

I WOULD LIKE TO KNOW IF YOU COULD CREATE A VERSION WITH THE FOLLOWING OPTIONS.

1) SELECT OBJECTS, OR SELECT ALL ON THE COMMAND LINE

(initget 0 "ALL or Select")
(setq sel (getkword "\nSet selection system All / Select"))
(condition
((= sel "All")
(setq ss (ssget "_X" '((0 . "LWPOLYLINE,LINE,CIRCLE,ELLIPSE"))))
((= sel "Selectl")
(setq ss (ssget '((0 . "LWPOLYLINE,LINE,CIRCLE,ELLIPSE"))))

2) BE ABLE TO CONTINUE QUOTING IF NEEDED TO SELECT AGAIN, AND BE ABLE TO SWITCH BETWEEN "H V B" ON THE COMMAND LINE

(setq sel (getkword "\nDraw Horizontal, Vertical or Both dimensions <H V B> ?"))

MY BEST REGARDS

0 Likes
Message 47 of 61

hak_vz
Advisor
Advisor

@rolisonfelipe I'm currently flooded with work, so I'll work on your request during the weekend. 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 48 of 61

rolisonfelipe
Collaborator
Collaborator

Thank you very much, and a great job!
I will stay

0 Likes
Message 49 of 61

hak_vz
Advisor
Advisor

@rolisonfelipe  try this for a start, I'll make new version when I fine dome spare time.

(defun c:dimhorver_RF 
	;author hak_vz  
	;https://forums.autodesk.com/t5/user/viewprofilepage/user-id/5530556
	;Satuerday, May 18, 2024
	(
	/ *error* mappend mklist flatten take pointlist3d sset->enameList get_intersections get_intersection_points
	adoc ss enameList pt line_hor line_hor_obj line_ver line_ver_obj i j ph pv eo int_pts sel old_dim_assoc st
	)
	
	(defun *error* ( msg )
		(if (not (member msg '("Function cancelled" "quit / exit abort")))
			(princ)
		)
		(if (and adoc) (vla-endundomark adoc))
		(setvar 'cmdecho 1)
		(setvar 'DIMASSOC old_dim_assoc)
		(princ)
	)
	(defun take (amount lst / ret)(repeat amount (setq ret (cons (car lst) (take (1- amount) (cdr lst))))))
	(defun pointlist3d (lst / ret) (while lst (setq	ret (cons (take 3 lst) ret) lst (cdddr lst))) (reverse ret))
	(defun mappend (fn lst)(apply 'append (mapcar fn lst)))
	(defun mklist (x) (if (listp x) x (list x)))
	(defun flatten (exp)(mappend 'mklist exp))
	(defun sset->enameList (ss / i ret)
		; extracts elements name for all objects in a selection set into a list
		(if ss
			(repeat (setq i (sslength ss))
				(setq ret (cons (ssname ss (setq i (1- i))) ret))
			) ;_ end of repeat
		) ;_ end of if
	) ;_ end of defun
	(defun get_intersections	(obj1 obj2 / var)
		(setq var (vlax-variant-value (vla-intersectwith obj1 obj2 1)))
		(if (< 0 (vlax-safearray-get-u-bound var 1))(vlax-safearray->list var))
	)
	(defun get_intersection_points (obj1 obj2) (pointlist3d (get_intersections obj1 obj2)))
	(setq adoc (vla-get-activedocument (vlax-get-acad-object))) 
	(setq old_dim_assoc (getvar 'DIMASSOC))
	(setvar 'DIMASSOC 1)
	(setvar 'cmdecho 0)
	(setq i 1)
	(while 
			(if (= i 1)
				(progn
					(initget 1 "A S Q")
					(setq st (strcase(getkword "\nSelect all <A> make selection <S> or quit <Q>  <A/S/Q>: ")))
				)
				(progn
					(initget 1 "A S P Q")
					(setq st (strcase(getkword "\nSelect all <A> make selection <S>  previous <P> or quit <Q>  <A/S/P/Q>: ")))
				)
			)
			(setq i (1+ i))
		(cond 
			((= st "A")(setq ss (ssget "_X" '((0 . "LWPOLYLINE,LINE,CIRCLE,ELLIPSE")))))
			((= st "S")(setq ss (ssget '((0 . "LWPOLYLINE,LINE,CIRCLE,ELLIPSE")))))
			((= st "P")(if ss (setq ss ss) (setq ss nil)))
			((T (setq ss nil)))
		)
	    (cond 
			((and(and ss) (> (sslength ss) 0))
				(setq enameList (sset->enameList ss))
				(initget 1 "H V B")
				(setq sel (getkword "\nDraw Horizontal, Vertical or Both dimensions <H V B> ?"))
				(cond 
					((= sel "H")
						(setq pt (getpoint "\nPick a point for horizontal dimensions position >"))
					)
					((= sel "V")
						(setq pt (getpoint "\nPick a point for vertical dimensions position >"))
					)
					((= sel "B")
						(setq ph (getpoint "\nPick a point for horizontal dimensions position >"))
						(setq pv (getpoint "\nPick a point for vertical dimensions position >"))
						(setq pt (list (car pv) (cadr ph)))
					)	
				)
				
				(cond 
					((and pt)
						(vla-endundomark adoc)
						(vla-startundomark adoc)
						(setq line_ver
							(entmakex
								(list
									(cons 0 "XLINE")
									(cons 100 "AcDbEntity")
									(cons 100 "AcDbXline")
									(cons 10 (trans pt 1 0))
									(cons 11 '(0 1 0))
								)
							)
						)
						(setq line_ver_obj (vlax-ename->vla-object line_ver))
						(setq line_hor
							(entmakex
								(list
									(cons 0 "XLINE")
									(cons 100 "AcDbEntity")
									(cons 100 "AcDbXline")
									(cons 10 (trans pt 1 0))
									(cons 11 '(1 0 0))
								)
							)
						)
						(setq line_hor_obj (vlax-ename->vla-object line_hor))
						(cond 
							((or (= sel "H")(= sel "B"))
								
								(setq i -1)
								(while (< (setq i (1+ i)) (length enameList))
									(setq eo (vlax-ename->vla-object (nth i enameList)))
									(setq ipts (get_intersection_points line_hor_obj eo))
									
									(if (and ipts) (setq int_pts (cons ipts int_pts)))
								)
								(cond 
									((and int_pts)
										(setq int_pts (vl-sort (flatten int_pts) '(lambda (x y) (< (car x)(car y)))))
										(setq j -1)
										(while (< (setq j (1+ j)) (1- (length int_pts)))
											(command "_.dimhorizontal" (nth j int_pts)(nth (1+ j) int_pts)(nth (1+ j) int_pts))
										)
									)
								)
								(setq int_pts nil)
							)
						)
						(cond 
							((or (= sel "V")(= sel "B"))
								(setq i -1)
								(while (< (setq i (1+ i)) (length enameList))
									(setq eo (vlax-ename->vla-object (nth i enameList)))
									(setq ipts (get_intersection_points line_ver_obj eo))
									(if (and ipts) (setq int_pts (cons ipts int_pts)))				
								)
								
								(cond 
									((and int_pts)
										(setq int_pts (vl-sort (flatten int_pts) '(lambda (x y) (< (cadr x)(cadr y)))))
										(setq j -1)
										(while (< (setq j (1+ j)) (1- (length int_pts)))
											(command "_.dimvertical" (nth j int_pts)(nth (1+ j) int_pts)(nth (1+ j) int_pts))
										)
									)
								)
								(setq int_pts nil)
							)
						)
						(if (and eo)(vlax-release-object eo))
						(if (and line_hor_obj)(vlax-release-object line_hor_obj))
						(if (and line_ver_obj)(vlax-release-object line_ver_obj))	
						(entdel line_hor)
						(entdel line_ver)
						(vla-endundomark adoc)
					)
				)
				
				
			)
			((T nil))			
		)
	)
(*error*)
(princ "\nDone!") 
(princ)
)

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 50 of 61

17ngo01ni84
Contributor
Contributor

How can we have this pick hole centres and not diameters?

0 Likes
Message 51 of 61

hak_vz
Advisor
Advisor

@17ngo01ni84  Start a new post (request), describe what you need and attach sample drawing. This code use intersection with objects and doesn0 take its properties (i.em circle center). I could modify my code but need some sample drawing for guidance. So, start new post!

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 52 of 61

17ngo01ni84
Contributor
Contributor

dimensioning as below

 

Pearson_Mhurudzekunze_0-1716277378882.png

Sample as below

0 Likes
Message 53 of 61

Kent1Cooper
Consultant
Consultant

QDIM will do pretty much exactly that.

[If by "sample" you meant to attach a drawing file, it didn't attach.  If you were trying by replying to an email notice that someone replied to your earlier one, you can't attach things that way.  You must come to the website in a "real" browser.]

Kent Cooper, AIA
0 Likes
Message 54 of 61

17ngo01ni84
Contributor
Contributor

I understand but Qdim is slow. I will have hundreds of these objects that need dimensioning and comes in different sizes. When i use QDIM, i then need to delete all the dimensions between these objects as I only need dimensions to appear on the individual object and not between them. This is quite time consuming. This LISP works perfectly for what I want but I need it to pick distances between centres. That's the only enhancement that I need.

 

 

0 Likes
Message 55 of 61

Kent1Cooper
Consultant
Consultant

Getting back to the procedure in the original Message:  Are you talking about picking at one spot inside an outline that has some Circles inside it, and getting Dimensions as in your image, not just the overalls as in the original?  Or is it your intent to select all the Circles and the outline parts?  Or something else?

Kent Cooper, AIA
0 Likes
Message 56 of 61

17ngo01ni84
Contributor
Contributor

I need to dimension from the outline, passes through hole centres and ends at the the other side

my desired result is as below

 

Pearson_Mhurudzekunze_0-1716305517761.png

 

0 Likes
Message 57 of 61

Kent1Cooper
Consultant
Consultant

That doesn't fully answer my question.  Supposing a custom command, you would call the command name, and then you would expect to....

Select all the Circles and the whole box around them, all together?  Or only one direction's worth at a time?  Select the Circles only, and somehow use the functionality from earlier routines in this topic to find the boundary Lines?  Just pick inside the box and have the routine find the Circles?  How would the position of the dimension lines be determined -- by User pick or somehow calculated by the routine?  Etc., etc.

Kent Cooper, AIA
0 Likes
Message 58 of 61

marko_ribar
Advisor
Advisor

I coded something for circles and recorded video... It is connected with your example shown at picture...

 

(defun c:qdimcents ( / *error* foo cmd osm bp ch chh )

  (or (not (vl-catch-all-error-p (vl-catch-all-apply (function vlax-get-acad-object) nil))) (vl-load-com))

  (defun *error* ( m )
    (while (= 8 (logand 8 (getvar (quote undoctl))))
      (if command-s
        (command-s "_.undo" "_e")
        (vl-cmdf "_.undo" "_e")
      )
    )
    (if osm
      (setvar (quote osmode) osm)
    )
    (if cmd
      (setvar (quote cmdecho) cmd)
    )
    (if m
      (prompt m)
    )
    (princ)
  )

  (defun foo ( mode bp ch / p xl s ss entlst pl plst pll )
    (vl-cmdf "_.xline" bp (if (= mode 1) (polar bp 0.0 1.0) (polar bp (* 0.5 pi) 1.0)))
    (while (< 0 (getvar (quote cmdactive)))
      (vl-cmdf "")
    )
    (setq xl (entlast))
    (if (setq s (ssget "_A" (list (cons 0 "*POLYLINE,LINE"))))
      (cond
        ( (vl-every (function (lambda ( x ) (= (cdr (assoc 0 (entget x))) "LINE"))) (setq entlst (mapcar (function cadr) (ssnamex s))))
          (foreach ent entlst
            (if (setq p (vlax-invoke (vlax-ename->vla-object xl) (quote intersectwith) (vlax-ename->vla-object ent) acextendnone))
              (if (= (length p) 3)
                (setq pl (cons p pl))
              )
            )
          )
        )
        ( (vl-every (function (lambda ( x ) (wcmatch (cdr (assoc 0 (entget x))) "*POLYLINE"))) (setq entlst (mapcar (function cadr) (ssnamex s))))
          (foreach ent entlst
            (if (setq p (vlax-invoke (vlax-ename->vla-object xl) (quote intersectwith) (vlax-ename->vla-object ent) acextendnone))
              (if (= (length p) 6)
                (setq pl (cons (list (car p) (cadr p) (caddr p)) pl) pl (cons (list (nth 3 p) (nth 4 p) (nth 5 p)) pl))
                (setq pl (cons p pl))
              )
            )
          )
        )
      )
    )
    (setq pl (mapcar (function (lambda ( p ) (trans p 0 1))) pl))
    (setq pl (vl-sort pl (function (lambda ( a b ) (< (if (= mode 1) (car a) (cadr a)) (if (= mode 1) (car b) (cadr b)))))))
    (if (setq ss (ssget "_A" (list (cons 0 "CIRCLE"))))
      (progn
        (setq entlst (mapcar (function cadr) (ssnamex ss)))
        (setq plst (mapcar (function (lambda ( x ) (trans (cdr (assoc 10 (entget x))) 0 1))) entlst))
        (setq plst (vl-remove-if (function (lambda ( x ) ((if (= ch "UpperRight") < >) (if (= mode 1) (cadr x) (car x)) (if (= mode 1) (cadr bp) (car bp))))) plst))
        (setq plst (vl-sort plst (function (lambda ( a b ) (< (if (= mode 1) (car a) (cadr a)) (if (= mode 1) (car b) (cadr b)))))))
        (setq plst (vl-remove-if-not (function (lambda ( x ) (< (if (= mode 1) (caar pl) (cadar pl)) (if (= mode 1) (car x) (cadr x)) (if (= mode 1) (caadr pl) (cadadr pl))))) plst))
        (setq plst (mapcar (function (lambda ( x ) (list (if (= mode 1) (car x) (car bp)) (if (= mode 1) (cadr bp) (cadr x)) 0.0))) plst))
        (setq pl (append (list (car pl)) plst (list (cadr pl))))
        (if (and xl (not (vlax-erased-p xl)))
          (entdel xl)
        )
        (setq pll (mapcar (function (lambda ( a b ) (list a b))) pl (cdr pl)))
        (foreach pp pll
          (vl-cmdf "_.dimlinear" (car pp) (cadr pp) (polar (polar (car pp) (angle (car pp) (cadr pp)) (/ (distance (car pp) (cadr pp)) 2.0)) (+ (angle (car pp) (cadr pp)) (* 0.5 pi)) (getvar (quote dimasz))))
          (while (< 0 (getvar (quote cmdactive)))
            (vl-cmdf "")
          )
        )
      )
    )
  )

  (setq cmd (getvar (quote cmdecho)))
  (setvar (quote cmdecho) 0)
  (setq osm (getvar (quote osmode)))
  (setvar (quote osmode) 0)
  (setvar (quote textsize) (* 2.0 (getvar (quote dimasz))))
  (while (= 8 (logand 8 (getvar (quote undoctl))))
    (vl-cmdf "_.undo" "_e")
  )
  (vl-cmdf "_.undo" "_be")
  (initget 1 "UpperRight LowerLeft")
  (setq ch (getkword "\nChoose option [UpperRight/LowerLeft] : "))
  (initget "X Y Both")
  (setq chh (cond ( (getkword "\nDo you want dimensioning parallel with axises [X/Y/Both]  : ") ) ( "Both" )))
  (initget 1)
  (setq bp (getpoint "\nPick or specify point : "))
  (cond
    ( (= chh "Both")
      (foo 1 bp ch)
      (foo 2 bp ch)
    )
    ( (= chh "X")
      (foo 1 bp ch)
    )
    ( (= chh "Y")
      (foo 2 bp ch)
    )
  )
  (*error* nil)
)

HTH.

M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 59 of 61

17ngo01ni84
Contributor
Contributor

You re the BEST!!!

0 Likes
Message 60 of 61

17ngo01ni84
Contributor
Contributor

@Kent1Cooper look at the solution from @marko_ribar . That's all i wanted