Author Topic: Grread - dynamic sizing/position of circle  (Read 6975 times)

0 Members and 1 Guest are viewing this topic.

deanby7

  • Guest
Grread - dynamic sizing/position of circle
« on: January 27, 2017, 07:56:49 PM »
I wonder whether anyone can help with the code below. I'm trying to position a circle on a polyline (simulating osnap 'near') using mouse, and simultaneously being able to resize the circle to 4 four radii options by pressing 1,2, 3 or 4 on the keyboard. The circle moves as expected up and down the polyline and is fixed with a left click. However, when pressing keys 1, 2,3 or 4 the circle only temporarily resizes in the original circle position! The 'entmod' function does not appear to be modifying the entity. I'm missing something simple I think!!
Any ideas/help would be most apreciated.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Grread - dynamic sizing/position of circle
« Reply #1 on: January 27, 2017, 08:32:34 PM »
Consider that when updating the circle position, you are using the original DXF data, as opposed to the DXF data which may hold a different radius value.

I would personally suggest:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:gg ( / cir ent grr lst rad sel )
  2.     (setq lst
  3.        '(
  4.             (49 . 12.78)
  5.             (50 . 15.78)
  6.             (51 . 18.78)
  7.             (52 . 21.78)
  8.         )
  9.     )
  10.     (if (setq sel (ssget "_+.:E:S" '((0 . "LWPOLYLINE"))))
  11.         (progn
  12.             (setq ent (ssname sel 0)
  13.                   cir (cons -1 (entmakex (list '(0 . "CIRCLE") '(10 1e8 1e8) (cons 40 (cdar lst)))))
  14.             )
  15.             (while (/= 3 (car (setq grr (grread t 15 0))))
  16.                 (cond
  17.                     (   (= 5 (car grr))
  18.                         (entmod (list cir (cons 10 (vlax-curve-getclosestpointto ent (cadr grr)))))
  19.                     )
  20.                     (   (= 2 (car grr))
  21.                         (if (setq rad (cdr (assoc (cadr grr) lst)))
  22.                             (entmod (list cir (cons 40 rad)))
  23.                         )
  24.                     )
  25.                 )
  26.             )
  27.         )
  28.     )
  29.     (princ)
  30. )

Note that the above is only a draft and doesn't account for UCS/Views etc.

deanby7

  • Guest
Re: Grread - dynamic sizing/position of circle
« Reply #2 on: January 28, 2017, 02:40:37 AM »
Brilliant! Thanks Lee

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Grread - dynamic sizing/position of circle
« Reply #3 on: January 28, 2017, 05:15:36 AM »
Brilliant! Thanks Lee

Indeed. That assoc lst he used is brilliant!
Got me thinking that something can be written like action_tile, but it would work for grread instead of dialog.
Just leaving the idea. :idea:
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Grread - dynamic sizing/position of circle
« Reply #4 on: January 28, 2017, 07:59:51 AM »
Thank you both  :-)

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Grread - dynamic sizing/position of circle
« Reply #5 on: February 02, 2017, 01:16:33 PM »
Consider that when updating the circle position, you are using the original DXF data, as opposed to the DXF data which may hold a different radius value.

I would personally suggest:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:gg ( / cir ent grr lst rad sel )
  2.     (setq lst
  3.        '(
  4.             (49 . 12.78)
  5.             (50 . 15.78)
  6.             (51 . 18.78)
  7.             (52 . 21.78)
  8.         )
  9.     )
  10.     (if (setq sel (ssget "_+.:E:S" '((0 . "LWPOLYLINE"))))
  11.         (progn
  12.             (setq ent (ssname sel 0)
  13.                   cir (cons -1 (entmakex (list '(0 . "CIRCLE") '(10 1e8 1e8) (cons 40 (cdar lst)))))
  14.             )
  15.             (while (/= 3 (car (setq grr (grread t 15 0))))
  16.                 (cond
  17.                     (   (= 5 (car grr))
  18.                         (entmod (list cir (cons 10 (vlax-curve-getclosestpointto ent (cadr grr)))))
  19.                     )
  20.                     (   (= 2 (car grr))
  21.                         (if (setq rad (cdr (assoc (cadr grr) lst)))
  22.                             (entmod (list cir (cons 40 rad)))
  23.                         )
  24.                     )
  25.                 )
  26.             )
  27.         )
  28.     )
  29.     (princ)
  30. )

Note that the above is only a draft and doesn't account for UCS/Views etc.
Has anyone tried this function in Bricscad?

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Grread - dynamic sizing/position of circle
« Reply #6 on: February 03, 2017, 03:45:47 AM »
Version for Bricscad:
Code: [Select]
(defun c:ggB ( / EntDat ent grr lst rad sel )
   (setq lst
      '(
           (49 . 12.78)
           (50 . 15.78)
           (51 . 18.78)
           (52 . 21.78)
       )
   )
    (if (setq sel (ssget "_+.:E:S" '((0 . "LWPOLYLINE"))))
        (progn
            (setq ent    (ssname sel 0)
                  EntDat (entget (entmakex (list '(0 . "CIRCLE") '(10 1e8 1e8) (cons 40 (cdar lst)))))
            )
            (while (/= 3 (car (setq grr (grread t 15 0))))
                (cond
                    (   (= 5 (car grr))
                        (setq EntDat (entmod (subst (cons 10 (vlax-curve-getclosestpointto ent (cadr grr))) (assoc 10 EntDat) EntDat)))
                    )
                    (   (= 2 (car grr))
                        (if (setq rad (cdr (assoc (cadr grr) lst)))
                          (setq EntDat (entmod (subst (cons 40 rad) (assoc 40 EntDat) EntDat)))
                        )
                    )
                )
            )
        )
    )
    (princ)
)

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Grread - dynamic sizing/position of circle
« Reply #7 on: February 03, 2017, 08:05:01 AM »
Thank you Marc, I wasn't aware that BricsCAD could not modify entities using only the entity name group & groups to be modified.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Grread - dynamic sizing/position of circle
« Reply #8 on: February 03, 2017, 08:18:33 AM »
 
Thank you Marc, I wasn't aware that BricsCAD could not modify entities using only the entity name group & groups to be modified.
:-) Prego.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Grread - dynamic sizing/position of circle
« Reply #9 on: February 05, 2017, 02:06:17 PM »
Thank you Marc, I wasn't aware that BricsCAD could not modify entities using only the entity name group & groups to be modified.
:-) Prego.
... Alternatively the vle-entmod function can be used.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Grread - dynamic sizing/position of circle
« Reply #10 on: February 06, 2017, 04:22:11 AM »
Thank you Marc, I wasn't aware that BricsCAD could not modify entities using only the entity name group & groups to be modified.
:-) Prego.
... Alternatively the vle-entmod function can be used.
Ok, but the problem is that is not compatible with AutoCAD...  :cry:

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Grread - dynamic sizing/position of circle
« Reply #11 on: February 06, 2017, 08:02:58 AM »
Ok, but the problem is that is not compatible with AutoCAD...  :cry:
Try sending in a Support Request.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Grread - dynamic sizing/position of circle
« Reply #12 on: February 06, 2017, 08:55:00 AM »
Write a function that branches on loading, defining (for the life time of the session) a wrapper (say _entmod) that sports the same interface regardless the platform but internally invokes vle-entmod | entmod appropriately.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Grread - dynamic sizing/position of circle
« Reply #13 on: February 06, 2017, 09:20:29 AM »
Write a function that branches on loading, defining (for the life time of the session) a wrapper (say _entmod) that sports the same interface regardless the platform but internally invokes vle-entmod | entmod appropriately.
Yes maybe it is the best solution ... but I seem to remember that AutoCAD does not support the method using entmod with only the entity name for all entities...

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Grread - dynamic sizing/position of circle
« Reply #14 on: February 06, 2017, 12:45:22 PM »
I seem to remember that AutoCAD does not support the method using entmod with only the entity name for all entities...

Correct - but Circles are supported.

I have this in my notes:

TYPE      MODIFIED USING ONLY ENAME?
=====================================
ARC                   YES
ATTRIB (SINGLE)       YES
ATTRIB (MULTI)        NO
CIRCLE                YES
ELLIPSE               NO
HATCH                 NO
INSERT                YES
LINE                  YES
LWPOLYLINE            NO
MTEXT                 NO
POINT                 YES
POLYLINE              YES
SPLINE                NO
TEXT                  YES
XLINE                 NO