QDIM BLOCK

QDIM BLOCK

Ahmed_204
Enthusiast Enthusiast
3,174 Views
13 Replies
Message 1 of 14

QDIM BLOCK

Ahmed_204
Enthusiast
Enthusiast

Good day ,

 

I would like to change something in this code that instead of choosing "pt" as dimension line location , I would like to see all the dimensions appear  after that choose where to put them. "The same idea of QDIM"

(vl-load-com)

(defun C:FH ( / *error* doc oVAR ss i pts ptsx ptsy d d0 filter)

   (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nError: " errmsg)))
    (foreach e oVAR (setvar (car e) (cdr e)))
    (vla-endundomark doc)
    (princ))

  ;------------------------------------------------------------------------------------------------------
  
  (vla-startundomark (setq doc (vla-get-activedocument (vlax-get-acad-object))))
  (foreach e '(CMDECHO ORTHOMODE)
    (setq oVAR (cons (cons e (getvar e)) oVAR)))

  (setvar 'CMDECHO 	0)
  (setvar 'ORTHOMODE 	0)

 

  
  
  
  (if (and (princ "\nNeed blocks, ")
               (setq ss (ssget (list '(0 . "INSERT"))))
	   (< 1 (setq i (sslength ss)))
	   (while (not (minusp (setq i (1- i))))
	     (setq pts (cons (cdr (assoc 10 (entget (ssname ss i)))) pts)))
	   (setq ptsx (vl-sort pts '(lambda (p q) (< (car  p) (car  q)))))
	   (setq ptsy (vl-sort pts '(lambda (p q) (< (cadr p) (cadr q)))))

	   (setq d (abs (/ (- (car  (last ptsx)) (caar  ptsx))      ;xmax-xmin
			   (if (zerop (setq d0 (- (cadr (last ptsy)) (cadar ptsy)))) ;ymax-ymin
			     0.001
			     d0))))

	   
	   (setq pt (getpoint "\nSpecify dimension line location: "))

	   (or *DimTypeBDA
	       (setq *DimTypeBDA "Aligned"))
	   (not (initget "Horizontal Vertical Aligned"))
	   (setq *DimTypeBDA (cond ((getkword (strcat "\nType of dimension ["
						      (cond ((> d 1000.) (if (= *DimTypeBDA "Vertical") (setq *DimTypeBDA "Horizontal")) "Horizontal")
							    ((< d 0.001) (if (= *DimTypeBDA "Horizontal") (setq *DimTypeBDA "Vertical")) "Vertical")
							    ("Horizontal/Vertical"))
						      "/Aligned] <" *DimTypeBDA ">: ")))
				   (*DimTypeBDA)))

	   (setq pts (if (or (= *DimTypeBDA "Horizontal")
			     (and (= *DimTypeBDA "Aligned")
				  (> (- (car (last ptsx))  (caar ptsx))
				     (- (cadr (last ptsy)) (cadar ptsy)))))
		       ptsx
		       ptsy))
	   
	

	   (setq i 0)
 
	   
	   )

    
    (repeat (1- (length pts))  
  
      (cond ((= *DimTypeBDA "Horizontal")
	     (command "_.DIMLINEAR"
			"_none" (nth i pts)
			"_none" (nth (1+ i) pts)
			"_H"
		      "_none" pt))
	    
	    ((= *DimTypeBDA "Vertical")
	       (command "_.DIMLINEAR"
			"_none" (nth i pts)
			"_none" (nth (1+ i) pts)
			"_V"
			"_none" pt))
	    
	    (T ;Aligned
	       (command "_.DIMALIGNED"
			"_none" (nth i pts)
			"_none" (nth (1+ i) pts)
			"_none" pt)))



      (setq i (1+ i))
      )

    

    (princ (strcat "\nError: Wrong selection of at least 2 BLOCKS.")))

  (foreach e oVAR (setvar (car e) (cdr e)))
  (vla-endundomark doc)
  (princ)
)
0 Likes
Accepted solutions (1)
3,175 Views
13 Replies
Replies (13)
Message 2 of 14

devitg
Advisor
Advisor

Would you, please, upload the sample.dwg, with and before and after?

 

0 Likes
Message 3 of 14

Ahmed_204
Enthusiast
Enthusiast

Good Day,

I don't know how to show you this on a sample drawing but I will tell you exactly what I need.

when you try this code you will find that all the dimensions will appear one time at the end of executing the code in    the location of point "pt".

I want all the dimension to appear first after that i click where i want to place those dimensions like exactly what you do while using QDIM command in Autocad.

Thank you for your support.

 

0 Likes
Message 4 of 14

CADaSchtroumpf
Advisor
Advisor

Hi,

Perhaps this?

(vl-load-com)

(defun C:FH ( / *error* doc oVAR ss i pts ptsx ptsy d d0 filter)

   (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nError: " errmsg)))
    (foreach e oVAR (setvar (car e) (cdr e)))
    (vla-endundomark doc)
    (princ))

  ;------------------------------------------------------------------------------------------------------
  
  (vla-startundomark (setq doc (vla-get-activedocument (vlax-get-acad-object))))
  (foreach e '(CMDECHO ORTHOMODE)
    (setq oVAR (cons (cons e (getvar e)) oVAR)))

  (setvar 'CMDECHO 	0)
  (setvar 'ORTHOMODE 	0)

 

  
  
  
  (if (and (princ "\nNeed blocks, ")
               (setq ss (ssget (list '(0 . "INSERT"))))
	   (< 1 (setq i (sslength ss)))
	   (while (not (minusp (setq i (1- i))))
	     (setq pts (cons (cdr (assoc 10 (entget (ssname ss i)))) pts)))
	   (setq ptsx (vl-sort pts '(lambda (p q) (< (car  p) (car  q)))))
	   (setq ptsy (vl-sort pts '(lambda (p q) (< (cadr p) (cadr q)))))

	   (setq d (abs (/ (- (car  (last ptsx)) (caar  ptsx))      ;xmax-xmin
			   (if (zerop (setq d0 (- (cadr (last ptsy)) (cadar ptsy)))) ;ymax-ymin
			     0.001
			     d0))))

	   
	   ;(setq pt (getpoint "\nSpecify dimension line location: "))

	   (or *DimTypeBDA
	       (setq *DimTypeBDA "Aligned"))
	   (not (initget "Horizontal Vertical Aligned"))
	   (setq *DimTypeBDA (cond ((getkword (strcat "\nType of dimension ["
						      (cond ((> d 1000.) (if (= *DimTypeBDA "Vertical") (setq *DimTypeBDA "Horizontal")) "Horizontal")
							    ((< d 0.001) (if (= *DimTypeBDA "Horizontal") (setq *DimTypeBDA "Vertical")) "Vertical")
							    ("Horizontal/Vertical"))
						      "/Aligned] <" *DimTypeBDA ">: ")))
				   (*DimTypeBDA)))

	   (setq pts (if (or (= *DimTypeBDA "Horizontal")
			     (and (= *DimTypeBDA "Aligned")
				  (> (- (car (last ptsx))  (caar ptsx))
				     (- (cadr (last ptsy)) (cadar ptsy)))))
		       ptsx
		       ptsy))
	   
	

	   (setq i 0)
 
	   
	   )

    
    (repeat (1- (length pts))  
  
      (cond ((= *DimTypeBDA "Horizontal")
	     (command "_.DIMLINEAR"
			"_none" (nth i pts)
			"_none" (nth (1+ i) pts)
			"_H"
		      "_none" pause))
	    
	    ((= *DimTypeBDA "Vertical")
	       (command "_.DIMLINEAR"
			"_none" (nth i pts)
			"_none" (nth (1+ i) pts)
			"_V"
			"_none" pause))
	    
	    (T ;Aligned
	       (command "_.DIMALIGNED"
			"_none" (nth i pts)
			"_none" (nth (1+ i) pts)
			"_none" pause)))



      (setq i (1+ i))
      )

    

    (princ (strcat "\nError: Wrong selection of at least 2 BLOCKS.")))

  (foreach e oVAR (setvar (car e) (cdr e)))
  (vla-endundomark doc)
  (princ)
)
Message 5 of 14

Ahmed_204
Enthusiast
Enthusiast

Hi,

I tried to solve it like that yesterday but it will keep asking the user for the dimension location for each dimension created between blocks because the Dimlinear inside a repeat loop.

I want the lisp to create all the dimension first and show it on screen and wait for the user to choose the location.

I am thinking about storing all the dimensions created in a variable then delete them and call this variable which will  allow the user to put the dimension in the desired location. "Just an idea"

 Thanks.

0 Likes
Message 6 of 14

devitg
Advisor
Advisor

Please upload a sample.dwg with such  INSERT'ed  blocks . It just what I need to check your lisp 

 

0 Likes
Message 7 of 14

Ahmed_204
Enthusiast
Enthusiast

Good Day , 

I attached a sample drawing.

Thanks for your support.

0 Likes
Message 8 of 14

Ahmed_204
Enthusiast
Enthusiast

HI @cadffm ,

 

Can you support me in this issue as well ?

 

Thanks for your support.

0 Likes
Message 9 of 14

phanaem
Collaborator
Collaborator

Hi

I use this lisp to QDIM blocks. It works like native QDIM, but allows blocks to be selected and measure at the insertion point.

If you want only blocks, change this line ... (setq ss1 (ssadd) ss (ssget '((0 . "INSERT))))

 

(defun c:qqd ( / *error* acDoc ss1 ss i e)
  (setq acDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (vla-StartUndoMark acDoc)
  
  (defun *error* (msg / i)
    (if
      (not (eq msg "Function cancelled"))
      (princ msg)
      )
    (repeat (setq i (sslength ss1)) (entdel (ssname ss1 (setq i (1- i)))))
    (vla-EndUndoMark acDoc)
  )
  
  (if
    (setq ss1 (ssadd) ss (ssget))
    (progn
      (repeat (setq i (sslength ss))
        (if
          (eq (cdr (assoc 0 (entget (setq e (ssname ss (setq i (1- i))))))) "INSERT")
          (ssadd (entmakex (list '(0 . "POINT") (assoc 10 (entget e)))) ss1)
        )
      )
      (command "_QDIM" ss ss1 "")
      (while (> (getvar 'cmdactive) 0)
        (command pause)
      )
    )
  )
  (*error* nil)
  (princ)
)

 

0 Likes
Message 10 of 14

cadffm
Consultant
Consultant

I guess you need two things:

 

a) How to identifier depend the cursor position (first step simply use one static sample/your sample.dwg and three different static coordinates as cursorposition for H/V/A)

b) Read about GRREAD to read coordinates of cursorposition and more.

 

 

Sorry, now time to show all the way.

 

GoodLuck, you will find a lot of samples in www

The Preview is not a problem, just create your dimensions..

you can delete&re-create or edit the dimension easily.

 

S

Sebastian

Message 11 of 14

Ahmed_204
Enthusiast
Enthusiast

Hi @phanaem

 

Your Solution would be perfect if it applies also with aligned dimension but its also good.

 

Thank you for your support.

0 Likes
Message 12 of 14

Ahmed_204
Enthusiast
Enthusiast
Accepted solution

Good Day , 

 

I found the solution for this issue by getting support from CadTutor

 

I attached the final lisp here.

 

Thank you all for your support & effort.

 

Message 13 of 14

arpansark0544TCX
Advocate
Advocate
This lisp is very useful. Thank you
Message 14 of 14

Ahmed_204
Enthusiast
Enthusiast

You are welcome @arpansark0544TCX