Recent Posts

Pages: [1] 2 3 ... 10
1
AutoLISP (Vanilla / Visual) / Re: Check if clip is present in the drawing
« Last post by xdcad on Today at 05:21:12 AM »
CLIP information is stored in the extended dictionary of the AcDbBlockReference (INSERT) object,

The Inspector tool can view



You can traverse all INSERTs to determine whether there is ACAD_FILTER


Code - Auto/Visual Lisp: [Select]
  1. (defun XD::Doc:HasFILTER (/ SS i bFound dict)
  2.   (if (setq ss (ssget "x" '((0 . "Insert"))))
  3.     (progn
  4.       (setq i -1
  5.             bFound t
  6.       )
  7.       (while (and bFound (setq e (ssname ss (setq i (1+ i)))))
  8.         (setq ed (entget e))
  9.         (if (and (setq dict (cdr (assoc 360 ed)))
  10.                  (= (cdr (assoc 3 (entget dict))) "ACAD_FILTER")
  11.             )
  12.           (setq bFound nil)
  13.         )
  14.       )
  15.       (not bFound)
  16.     )
  17.   )
  18. )
2
XDRX-API / [XDrX-PlugIn(159)] Create snake line over a circle
« Last post by xdcad on Today at 04:39:17 AM »
https://www.cadtutor.net/forum/topic/61650-create-snake-line-over-a-circle/

Code: [Select]
(defun c:xdtb_snakecircle (/ an box cir direc dist e1 e2 endln ents ents-pair ept1 ept2
       firstln garc i ints items ln1 ln2 mode p1extend pl ptmid pts1
       pts2 spt1 spt2 x y
    )
  (defun _make-sharp-corners (direc)
    (setq items (nth direc ents-pair)
  e1 (car items)
  e2 (cadr items)
  ept2 (xdrx-curve-getendpoint e2)
  spt2 (xdrx-curve-getstartpoint e2)
  spt1 (xdrx-curve-getstartpoint e1)
  ept1 (xdrx-curve-getendpoint e1)
    )
    (cond
      ((= (rem direc 2) 0)
(if (< direc (/ #xd-var-global-divide-nums 2.0))
  (progn
    (setq p1extend (xdrx-getpropertyvalue (list spt1 ept1)
  "getclosestpointto" ept2 t
   )
  ptmid (xdrx-line-midp ept2 p1extend)

    )
    (xdrx-curve-setsptept e1 ept1 p1extend)
    (if (= #xd-var-global-mode "1")
      (progn
(setq ptmid (polar ptmid 0 (distance ptmid ept2)))
(setq garc (xdge::constructor "kCircArc3d" p1extend ptmid
      ept2
   )
)
(xdrx-entity-make garc)
      )
      (progn
(setq ptmid (polar ptmid 0 (* (distance ptmid ept2) 1.3)))
(xdrx-line-make p1extend ptmid)
(xdrx-line-make ptmid ept2)
      )
    )
  )
  (progn
    (setq p1extend (xdrx-getpropertyvalue (list spt2 ept2)
  "getclosestpointto" ept1 t
   )
  ptmid (xdrx-line-midp ept1 p1extend)
    )
    (xdrx-curve-setsptept e2 ept2 p1extend)
    (if (= #xd-var-global-mode "1")
      (progn
(setq ptmid (polar ptmid 0 (distance ptmid ept1)))
(setq garc (xdge::constructor "kCircArc3d" p1extend ptmid
      ept1
   )
)
(xdrx-entity-make garc)
      )
      (progn
(setq ptmid (polar ptmid 0 (* (distance ptmid ept1) 1.3)))
(xdrx-line-make ept1 ptmid)
(xdrx-line-make ptmid p1extend)
      )
    )

  )
)
      )
      (t
(if (< direc (/ #xd-var-global-divide-nums 2.0))
  (progn

    (setq p1extend (xdrx-getpropertyvalue (list spt1 ept1)
  "getclosestpointto" spt2 t
   )
  ptmid (xdrx-line-midp spt2 p1extend)
    )
    (xdrx-curve-setsptept e1 spt1 p1extend)
    (if (= #xd-var-global-mode "1")
      (progn
(setq ptmid (polar ptmid pi (distance ptmid spt2)))
(setq garc (xdge::constructor "kCircArc3d" p1extend ptmid
      spt2
   )
)
(xdrx-entity-make garc)
      )
      (progn
(setq ptmid (polar ptmid pi (* (distance ptmid spt2) 1.3)))
(xdrx-line-make p1extend ptmid)
(xdrx-line-make ptmid spt2)
      )
    )
  )
  (progn
    (setq p1extend (xdrx-getpropertyvalue (list spt2 ept2)
  "getclosestpointto" spt1 t
   )
  ptmid (xdrx-line-midp spt1 p1extend)
    )
    (xdrx-curve-setsptept e2 spt2 p1extend)
    (if (= #xd-var-global-mode "1")
      (progn
(setq ptmid (polar ptmid pi (distance ptmid spt1)))
(setq garc (xdge::constructor "kCircArc3d" p1extend ptmid
      spt1
   )
)
(xdrx-entity-make garc)
      )
      (progn
(setq ptmid (polar ptmid pi (* (distance ptmid spt1) 1.3)))
(xdrx-line-make spt1 ptmid)
(xdrx-line-make ptmid p1extend)
      )
    )
  )
)
      )
    )
  )
  (setq #xd-var-global-mode "0")
  (xdrx-initget 0 "0 1")
  (if (setq mode (getkword (xdrx-string-formatex
(xdrx-string-multilanguage "\n模式[标准(0)/圆弧(1)]<1>" "\nMode[standard(0)/arc(1)]<%s>")
#xd-var-global-mode
   )
)
      )
    (setq #xd-var-global-mode mode)
  )
  (xdrx-initget)
  (xd::doc:getint (xdrx-string-multilanguage "\n等分数" "\nDivide Nums")
  "#xd-var-global-divide-nums" 20
  )
  (if (setq cir (car (xdrx-entsel (xdrx-string-multilanguage "\n拾取圆<退出>:" "\nPick Circle<Exit>:")
  '((0 . "circle"))
     )
)
      )
    (progn
      (xdrx-begin)
      (xdrx-setmark)
      (setq box (xdrx-entity-box cir)
    ln1 (list (nth 3 box) (nth 0 box))
    pts1 (xdrx-getpropertyvalue ln1 "getsamplepoints"
#xd-var-global-divide-nums
)
    ln2 (list (nth 2 box) (nth 1 box))
    pts2 (xdrx-getpropertyvalue ln2 "getsamplepoints"
#xd-var-global-divide-nums
)
    an (angle (car pts2) (car pts1))
    firstln (list (polar (car pts1) an (/ (distance (car pts1)
    (car pts2)
  ) 7.0
       )
  ) (car pts2)
    )
    an (angle (car pts1) (car pts2))
    dist (/ (distance (last pts1) (last pts2)) 7.0)
    endln (if (= (rem #xd-var-global-divide-nums 2) 1)
    (list (polar (last pts1) (+ an pi) dist) (last pts2))
    (list (last pts1) (polar (last pts2) an dist))
  )
    pts1 (cdr (xd::list:removetail pts1))
    pts2 (cdr (xd::list:removetail pts2))
    ents nil
      )
      (xdrx-line-make firstln)
      (setq ents (cons (entlast) ents))
      (mapcar
'(lambda (x y)
   (setq ints (xdrx-entity-intersectwith (list x y) cir)
ints (xdrx-points-sortoncurve (list x y) ints)
   )
   (apply
     'xdrx-line-make
     ints
   )
   (setq ents (cons (entlast) ents))
)
pts1
pts2
      )
      (xdrx-line-make endln)
      (setq ents (cons (entlast) ents)
    ents (reverse ents)
    ents-pair (xd::list:snakepair ents)
      )
      (setq i -1)
      (repeat (length ents-pair)
(setq i (1+ i))
(_make-sharp-corners i)
      )
      (xdrx-curve-join (xdrx-getss))
      (setq pl (entlast))
      (xdrx-entity-setcolor pl 1)
      (xdrx-end)
    )
  )
  (princ)
)
3
AutoLISP (Vanilla / Visual) / Re: entsel with ability enter numbers?
« Last post by V@no on Today at 04:36:22 AM »
Why not for 2 entities use entsel can have messages etc just do twice.
That's exactly what I'm using, except entsel doesn't allow arbitrary input, hence is the hack above.

You can use (ssget pt) which selects a single item (ssname ss 0) useful if you want to show a drag line.
and pt is a set of coordinates? I think you lost me on this one.
4
Thanks. problem solved :)

can you see this
http://www.theswamp.org/index.php?topic=22206.0;all

Code: [Select]

;; Entmatrix
;; Returns a list which first item is the 3X3 tranformation matrix and second item
;; the insertion point of a block refernce in its owner (space or block definition)
(defun EntMatrix (ename / elst ang norm)
  (setq elst (entget ename)
ang  (cdr (assoc 50 elst))
norm (cdr (assoc 210 elst))
  )
  (list
    (mxm
      (mapcar (function (lambda (v) (trans v 0 norm T)))
      '((1.0 0.0 0.0) (0.0 1.0 0.0) (0.0 0.0 1.0))
      )
      (mxm
(list (list (cos ang) (- (sin ang)) 0.0)
      (list (sin ang) (cos ang) 0.0)
      '(0.0 0.0 1.0)
)
(list (list (cdr (assoc 41 elst)) 0.0 0.0)
      (list 0.0 (cdr (assoc 42 elst)) 0.0)
      (list 0.0 0.0 (cdr (assoc 43 elst)))
)
      )
    )
    (trans (cdr (assoc 10 elst)) norm 0)
  )
)

;; Blk2Coord
;; Returns a list of a block reference entities coordinates
(defun Blk2Coord (ref mat ins / blk ent lst)
  (setq blk (tblsearch "BLOCK" (cdr (assoc 2 (entget ref)))))
  (setq ent (cdr (assoc -2 blk)))
  (while ent
    (setq elst (entget ent)
  typ  (cdr (assoc 0 elst))
    )
    (cond
      ((= "LINE" typ)
       (setq lst (cons (list typ
     (mapcar '+ ins (mxv mat (cdr (assoc 10 elst))))
     (mapcar '+ ins (mxv mat (cdr (assoc 11 elst))))
       )
       lst
)
       )
      )
      ((member typ '("POINT" "TEXT"))
       (setq lst (cons (list typ
     (mapcar '+ ins (mxv mat (cdr (assoc 10 elst))))
       )
       lst
)
       )
      )
      ((= "INSERT" typ)
       (setq nent (EntMatrix ent))
       (setq lst
      (append
lst
(Blk2Coord ent
   (mxm  mat (car nent))
   (mapcar '+ ins (mxv mat (cadr nent)))
)
      )
       )
      )
      (T nil)
    )
    (setq ent (entnext ent))
  )
  (cons (list (cdr (assoc 2 blk)) ins) lst)
)

;; Transpose a matrix Doug Wilson
(defun trp (m)
  (apply 'mapcar (cons 'list m))
)

;; Apply a transformation matrix to a vector by Vladimir Nesterovsky
(defun mxv (m v)
  (mapcar (function (lambda (r) (apply '+ (mapcar '* r v))))
  m
  )
)

;; Multiply two matrices by Vladimir Nesterovsky
(defun mxm (m q)
  (mapcar (function (lambda (r) (mxv (trp q) r))) m)
)

;; Main function

(defun c:test (/ ss n ent mtx lst)
  (if (setq ss (ssget '((0 . "INSERT"))))
    (repeat (setq n (sslength ss))
      (setq ent (ssname ss (setq n (1- n)))
    mtx (EntMatrix ent)
    lst (append (Blk2Coord ent (car mtx) (cadr mtx)) lst)
      )
    )
  )
  (mapcar 'print lst)
  (textscr)
  (princ)
)
5
AutoLISP (Vanilla / Visual) / Re: entsel with ability enter numbers?
« Last post by BIGAL on Today at 12:49:22 AM »
Why not for 2 entities use entsel can have messages etc just do twice.

Code: [Select]
(setq ent1 (car (entsel "\Please pick object 1 ")))
(setq ent2  (car (entsel "\Please pick object 2 ")))

You can use (ssget pt) which selects a single item (ssname ss 0) useful if you want to show a drag line.

6
BricsCAD Users / Block Selection from MS Office and Insert into DWG File
« Last post by CEHill on May 01, 2024, 06:09:02 PM »
Your thoughts and experiences on the subject line topic are appreciated.

Provide the overall level of difficulty, your preferred programming language, and the amount of coding needed to select and insert a drawing file from a link to that file from within in a MS Office application such as MS Excel or, ideally from our management's viewpoint, MS OneNote.

Are there more efficient means such as basing this development on another MS Office product or similar software up to and including a commercially available alternative over any custom-coded development.

From the local village: Due to complications of our cloud-based file storage, I have been told developing a database as in MS Access is not an alternative.

I have no experience in these types of development. Currently, I have beginner level coding skills but am familiar with program logic and willing to learn. 

Thanks,

Clint Hill 
7
XDRX-API / [XDrX-PlugIn(158)] Draw slope lines
« Last post by xdcad on May 01, 2024, 03:48:40 PM »
1.https://www.cadtutor.net/forum/topic/84274-lisp-for-slope-lines/

2.https://www.cadtutor.net/forum/topic/19901-draw-slope-lines

Code: [Select]
(defun c:xdtb_slopeline (/ an anbase arc1 bEnd c_pt cir1 cir2 e e1 e2 ept ept1 ept2
       even-list even-pair g int1 ints lastent lastents lst m midp
       mLn1 mLn2 mLn3 mode n_pt nearpt1 nearpt2 odd-list p1 p2 pnt
       pt r1 r2 spt1 spt2 ss temp temp1 top-pts1 vec1 vec2 x
    )
  (defun _get-perp-point (crv pnt)
    (mapcar
      '+
      pnt
      (xdrx-vector-perpvector (xdrx-curve-getfirstderiv e1 pnt))
    )
  )
  (defun _get-point (e pt / p1)
    (setq p1 (_get-perp-point e pt))
    (if (setq ints (xdrx-entity-intersectwith (list pt p1) e2 1))
      (car ints)
    )
  )
  (defun _get-next-circle-inters ()
    (if (and
  (setq n_pt (cadr (member c_pt even-list)))
  (setq int1 (_get-point e1 n_pt))
)
      (progn
(setq r2 (distance n_pt int1)
      cir2 (xdrx-circle-make int1 r2)
)
(setq lastents (cons cir2 lastents))
(setq ints (xdrx-entity-intersectwith cir1 cir2))
(setq nearpt2 (xdrx-points-nearpt c_pt ints))
      )
      (progn
(setq bEnd t
      m (xdrx-matrix-setmirror (list c_pt midp))
      nearpt2 (xdrx-point-transform nearpt1 m)

)
      )
    )
  )
  (defun _get-appropriate-angle ()
    (setq vec1 (mapcar
'-
nearpt1
midp
       )
  vec2 (mapcar
'-
nearpt2
midp
       )
    )
    (setq anbase (angle midp c_pt)
  an (xdrx-vector-angle vec2 vec1)
    )
    (if (> an #xd-var-global-slope-Angle)
      (progn
(setq p1 (polar midp (+ anbase (/ #xd-var-global-slope-Angle 2.0))
(distance midp c_pt)
)
      temp1 (xdrx-entity-intersectwith (list midp p1) cir1 1)
      nearpt1 (xdrx-points-nearpt p1 temp1)
)
(if (not bEnd)
  (progn
    (setq p2 (polar midp (- anbase (/ #xd-var-global-slope-Angle 2.0))
    (distance midp c_pt)
     )
  temp1 (xdrx-entity-intersectwith (list midp p2) cir1 1)
  nearpt2 (xdrx-points-nearpt p2 temp1)
    )
  )
  (setq nearpt2 (xdrx-point-transform nearpt1 m))
)
      )
    )
  )
  (defun _draw-slope-line ()
    (setq g (xdrx-curve-setinterval cir1 nearpt1 nearpt2))
    (setq arc1 (xdrx-entity-make g))
    (setq mLn1 (xdrx-line-make temp midp)
  mLn2 (xdrx-line-make
midp
(xdrx-curve-getstartpoint arc1)
       )
  mLn3 (xdrx-line-make
(xdrx-curve-getendpoint arc1)
midp
       )
    )
    (xdrx-curve-join (list mLn1 mLn2 arc1 mLn3))
    (if (= #xd-var-global-slope-mode "1")
      (progn
(xdrx-polyline-setbulgeat
  (entlast)
  1
  #xd-var-global-bulge
)
(xdrx-polyline-setbulgeat
  (entlast)
  3
  #xd-var-global-bulge
)
      )
    )
  )
  (defun _draw-slope-1 ()
    (xdrx-line-make (car top-pts1) (xdrx-curve-getstartpoint e2))
    (setq lastent (entlast)
  lastents (cons lastent lastents)
  bEnd nil
    )
    (mapcar
      '(lambda (x)
(setq c_pt x)
(if (setq int1 (_get-point e1 c_pt))
   (progn
     (setq temp int1
   midp (xdrx-line-midp c_pt temp)
     )
     (setq r1 (distance c_pt int1)
   cir1 (xdrx-circle-make int1 r1)
     )
     (setq lastents (cons cir1 lastents))
     (if (setq ints (xdrx-entity-intersectwith cir1 lastent))
       (progn
(setq nearpt1 (xdrx-points-nearpt c_pt ints))
(setq nearpt2 (_get-next-circle-inters))
(_get-appropriate-angle)
(_draw-slope-line)
(xdrx-entity-delete cir2)
(setq lastent cir1)
       )
     )
   )
)
       )
      even-list
    )
    (xdrx-entity-delete lastents)   
  )
  (defun _draw-short-slope-line (lst)
    (mapcar
      '(lambda (x)
(setq p1 (_get-perp-point e1 x))
(if (setq ints (xdrx-entity-intersectwith (list x p1) e2 1))
   (progn
     (xdrx-line-make x (xdrx-line-midp x (car ints)))
   )
)
       )
      lst
    )
  )
  (defun _draw-slope-0 ()
    (xdrx-line-make (car top-pts1) (xdrx-curve-getstartpoint e2))
    (mapcar
      '(lambda (x)
(setq p1 (_get-perp-point e1 x))
(if (setq ints (xdrx-entity-intersectwith (list x p1) e2 1))
   (progn
     (xdrx-line-make x (car ints))
     (setq ept x)
   )
)
       )
      (cdr odd-list)
    )
    (_draw-short-slope-line even-list)
  )        ; main
  (setq #xd-var-global-bulge -0.2      ;  BULGE values of arc segments on
       ; both sides
#xd-var-global-slope-color 8
#xd-var-global-slope-Angle (/ pi 2.25) ; max angle on both sides;
  )        ; Modify the color index you need
  (if (not #xd-var-global-slope-mode)
    (setq #xd-var-global-slope-mode "1")
  )
  (xdrx-begin)
  (xdrx-sysvar-push '("RetEntList" 1))
  (xd::doc:getdouble (xdrx-string-multilanguage "\n坡线间距"
"\nSlope Line Gap"
     ) "#xd-var-global-slope-gap" 10.0
  )
  (xdrx-initget 0 "0 1 2")
  (if (setq mode (getkword (xdrx-string-formatex
(xdrx-string-multilanguage "\n坡度线模式[标准(0)/圆弧(1)/模式(2)]<1>" "\nSlope line mode[standard(0)/arc(1)/mode(2)]<%s>")
#xd-var-global-slope-mode
   )
)
      )
    (setq #xd-var-global-slope-mode mode)
  )
  (xdrx-initget)
  (if (and
(setq e1 (car (xdrx-entsel (xdrx-string-multilanguage "\n拾取坡顶线<退出>:" "\nPick top line<Exit>:")
   '((0 . "*polyline,line") (-4 . "<not")
    (-4 . "&=")
    (70 . 1)
    (-4 . "not>")
   )
      )
)
)
(setq e2 (car (xdrx-entsel (xdrx-string-multilanguage "\n拾取坡底线<退出>:" "\nPick down line<Exit>:")
   '((0 . "*polyline,line") (-4 . "<not")
    (-4 . "&=")
    (70 . 1)
    (-4 . "not>")
   )
      )
)
)
      )
    (progn
      (xdrx-setmark)
      (setq spt1 (xdrx-curve-getstartpoint e1)
    ept1 (xdrx-curve-getendpoint e1)
    spt2 (xdrx-curve-getstartpoint e2)
    ept2 (xdrx-curve-getendpoint e2)
      )
      (if (< (distance spt1 ept1) (distance spt1 spt2))
(xdrx-curve-reverse e2)
      )
      (setq top-pts1 (xdrx-curve-getpointsatdist e1 (/ #xd-var-global-slope-gap
       2.0
    )
     )
    even-list (xd::list:even top-pts1)
    even-pair (xd::list:snakepair top-pts1)
    odd-list (xd::list:odd top-pts1)
      )
      (cond
((= #xd-var-global-slope-mode "0")
  (_draw-slope-0)
)
(t
  (_draw-slope-1)
)
      )
      (setq ss (xdrx-getss))
      (xdrx-entity-setcolor ss #xd-var-global-slope-color)
      (xdrx_group_make "*" ss)
    )
  )
  (xdrx-sysvar-pop)
  (xdrx-end)
  (princ)
)
8
Test it now...
I think that now is good for both and BricsCAD and AutoCAD...

Regards, M.R.
9
Just to add note...
I tested my mod. in BricsCAD and it behaves good, but in AutoCAD it's very buggy...
Sorry, but I may not find apropriate solution for both environments...
Regards...
10
Try this mod... But selection of grips were not preserved when selected the same entity and because of that added (GETSTRING) after (SSSETFIRST)...

Code - Auto/Visual Lisp: [Select]
  1. (DEFUN c:seltst ( / *error* loop num str hgl sss ss ent1 ent2 )
  2.  
  3.   (DEFUN *error* ( m )
  4.     (IF hgl
  5.       (SETVAR (QUOTE highlight) hgl)
  6.     )
  7.     (IF m
  8.       (PROMPT m)
  9.     )
  10.     (PRINC)
  11.   )
  12.  
  13.   (SETQ loop T)
  14.   (SETQ num 0)
  15.   (SETQ str "first")
  16.   (SETQ hgl (GETVAR (QUOTE highlight)))
  17.   (SETVAR (QUOTE highlight) 1)
  18.   (SETQ sss (SSADD))
  19.   (WHILE loop
  20.     (PRINC (STRCAT "\nSelect " str " item : "))
  21.     (IF (AND ent1 (SSMEMB ent1 ss))
  22.       (SSDEL ent1 ss)
  23.     )
  24.     (WHILE (OR (NOT ss) (AND ss (= (SSLENGTH ss) 0)))
  25.       (SETQ ss (SSGET "_+.:E:S"))
  26.     )
  27.     (COND
  28.       ( (AND ss (= (SSLENGTH ss) 1) (= num 0))
  29.         (SETQ ent1 (SSNAME ss 0))
  30.         (SETQ num (1+ num))
  31.         (SETQ str "second")
  32.         (SSADD ent1 sss)
  33.       )
  34.       ( T
  35.         (SETQ loop nil)
  36.         (IF (AND ss (= (SSLENGTH ss) 1) (EQ ent1 (SETQ ent2 (SSNAME ss 0))))
  37.           (PROGN
  38.             (SETQ loop T)
  39.             (SSDEL ent1 ss)
  40.           )
  41.           (IF (OR (NOT ss) (AND ss (= (SSLENGTH ss) 0)))
  42.             (SETQ loop T)
  43.           )
  44.         )
  45.         (IF (AND ent2 (NOT (EQ ent1 ent2)))
  46.           (SSADD ent2 sss)
  47.         )
  48.       )
  49.     )
  50.     (SSSETFIRST nil sss)
  51.     (IF (OR (AND ent1 (NOT ent2)) (AND ent1 ent2 (EQ ent1 ent2)))
  52.       (PROGN
  53.         (GETSTRING "\nENTER TO CONTINUE...")
  54.         (SSSETFIRST)
  55.       )
  56.     )
  57.   )
  58.   (PRINC "\nFirst item : ")
  59.   (PRINC ent1)
  60.   (PRINC "\nSecond item : ")
  61.   (PRINC ent2)
  62.   (*error* nil)
  63. )
  64.  

M.R.
Pages: [1] 2 3 ... 10