Jump to content

Recommended Posts

Posted (edited)

I am searching for a lisp code to recognizes and dimensions LINE or ARC objects located in the Wall-2D layers and blocks in the CLOSETS-2D layer. like the image

The dimension layer is DIM

The idea is  to pick 2  points like a line and automatic insert the dmensions. I use ZWCAD.

 

Thanks

1.png

Edited by mhy3sx
Posted

Yes I have something done like 40 years ago, but did you try QDIM is that in ZWCAD ?

Posted (edited)

Hi BIGAL, I have try QDIM but  working as

 

Quote

Select geometry to dimension :

 

The QDIM don't dimension the block (look the image)

 

I want to draw a line by specifying two points, to indicate where dimensions should be placed.

This line should only appear on the layers named WALLS-2D and CLOSETS-2D.

The WALLS-2D layer contains both lines and polylines, while the CLOSETS-2D layer contains blocks.

 

Thanks

Screenshot 2026-03-30 121348.png

Edited by mhy3sx
Posted

Drawing the line would also pick up 4 lines across the block. would maybe have to do a fence ssget. and if block draw a bounding box to pick up lines but even then could be inaccurate if not a square.

  • Agree 1
Posted

I find a solution. I craete a polyline ,then auto dimension the polyline and delete the polyline. Beter tahn nothing :)

 

Thanks

  • Agree 1
Posted (edited)

As suggested by @mhupp if you use a fence option you can find objects and get their intersection points do a sort based on start point. For the block would do a Bounding Box around the block. and get the left and right edge points, then do the dims. Yes just need a line from left to right for "intersectwith". You can set the correct layers when doing the SSGET "F".

 

If get time will dummy up your dwg and see what the code I have does.

Edited by BIGAL
Posted (edited)

A lot shorter then i thought. will only work on horizontal polyline. adj p3 list to affect the offset.

 

;;----------------------------------------------------------------------;;
;; Poly DIM acts like QDIM but allows user to select horizontal points.
;; https://www.cadtutor.net/forum/topic/99059-auto-dimension-lisp/
(defun c:PLDIM (/ ent pts p1 p2 p3 ang)
  (vl-load-com)
  (command "_.pline")
  (while (= 1 (getvar "cmdactive"))
    (command pause)
  )
  (setq ent (entlast))
  (setq pts (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget ent))))
  (while (cadr pts)
    (setq p1 (car pts)
          p2 (cadr pts)
          mid (mapcar '/ (mapcar '+ p1 p2) '(2 2 2))
          p3 (mapcar '+ mid '(0.0 2.0 0.0)) ;adj 2.0 for offset.
    )
    (command "_.DIMLINEAR" p1 p2 p3)
    (setq pts (cdr pts))
  )
  (entdel ent)
  (princ)
)

 

 

 

 

Edited by mhupp
  • Like 1
Posted (edited)

A slight variation on MHUPPS

 

 

(defun c:ADIM (/ pt1 pt2 MyLine MySS acount MyIntersect MyDistance MyDistances pta ptb)
  (defun LM:intersections ( ob1 ob2 mod / lst rtn ) ;; See Lee Mac website. Get intersection list
    (if (and (vlax-method-applicable-p ob1 'intersectwith)
             (vlax-method-applicable-p ob2 'intersectwith)
             (setq lst (vlax-invoke ob1 'intersectwith ob2 mod))
        )
        (repeat (/ (length lst) 3)
            (setq rtn (cons (list (car lst) (cadr lst) (caddr lst)) rtn)
                  lst (cdddr lst)
            )
        )
    )
    (reverse rtn)
  )

  (command "line" (setq pt1 (getpoint)) pause "") ; Draw reference line. Mod to polyline possible
  (setq MyLine (entlast))                         ; Reference line entity name
  (setq pt2 (getvar 'lastpoint))                  ; pt2 of reference line
  (setq MySS (ssget "_f" (list pt1 pt2)))         ; Selection set crossing reference line (fence). Add filters

  (setq acount 0)                                 ; a counter
  (while (< acount (sslength MySS))               ; Loop through selection set

(if (setq MyIntersect (LM:intersections (vlax-ename->vla-object MyLine)(vlax-ename->vla-object (ssname MySS acount)) acextendnone )) ; get the intersection points, reference line, selection set items
  (progn
    (foreach n MyIntersect
      (setq MyDistance (distance pt1 n)) ; get the distance SS item, start reference line
      (setq MyDistances (cons (cons MyDistance (list n)) MyDistances)) ;; add the intersection & point to a list
    ) ; end foreach
  ) ; end progn
) ; end if intersections

    (setq acount (+ acount 1))                   ; increase counter
  ) ; end while                                  ; end loop
  (command "erase" MyLine "")                    ; erase reference line

  (setq MyDistances (vl-sort MyDistances (function (lambda (pta ptb) (< (car pta)(car ptB) ))) )) ; sort by distance


  (setq acount 0)
  (while (< (+ acount 1) (length MyDistances))
    (setq p1 (car (cdr (nth acount MyDistances))))
    (setq p2 (car (cdr (nth (+ acount 1) MyDistances))))
    (setq mid (mapcar '/ (mapcar '+ p1 p2) '(2 2 2))) ; ripped of MHUPP
    (setq p3 (mapcar '+ mid '(0.0 2.0 0.0)))     ;adj 2.0 for offset. ; ripped of MUPP
    (command "_.DIMLINEAR" p1 p2 p3)             ; Ripped of MHUPP
    (setq acount (+ acount 1))
  ) ; end while

  (princ)
)

 

 

Edit: Corrected for polylines crossing reference line more than once

 

Edited by Steven P
  • Like 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...