Author Topic: Dynamic drawing and substitution of grread-function  (Read 37287 times)

0 Members and 1 Guest are viewing this topic.

Pepe

  • Newt
  • Posts: 85
Re: Dynamic drawing and substitution of grread-function
« Reply #15 on: March 06, 2008, 02:02:29 PM »
Hi Alexander!

A useful program, Dyndraw  :-)! Thank you for writing it.

I'm trying to write my first program using Dyndraw, and I found my first problem using the <input_flag>  1, "GovernedByOrthoMode".

Here's the code I wrote where i found the problem. It only draws a "elastic" red rectangle, nothing else.

When I use "ORTHOMODE" the rectangle doesn't follow the ortho directions. It only works using  <cursor_type> 1, "RectCursor" or 2, "RubberBand".

Is that a bug or I did anything wrong?

Code: [Select]
(defun grv (qb / an pa pb pc pd pm)
  (if lv (grvecs (subst 0 1 lv)))
  (setq pm (/ pi 2)
an (angle qa qb)
pa (polar qa (+ an pm) 0.25)
pb (polar qb (+ an pm) 0.25)
pc (polar qb (- an pm) 0.25)
pd (polar qa (- an pm) 0.25)
lv (list 1 pa pb 1 pb pc 1 pc pd 1 pd pa)
)
  (grvecs lv)
  qb
  )

(defun C:BLCK (/ lv qa qb)
  (arxload "dyndraw2004")
  (vl-acad-defun 'grv)
  (setq qa (getpoint "\nStartpoint: "))
  (while (null qb)
    (setq qb (dyndraw "grv" "\nTo Point: " "" 657 0 qa))
    )
  (princ)
  )

Alexander Rivilis

  • Bull Frog
  • Posts: 214
  • Programmer from Kyiv (Ukraine)
Re: Dynamic drawing and substitution of grread-function
« Reply #16 on: March 06, 2008, 11:57:50 PM »
When I use "ORTHOMODE" the rectangle doesn't follow the ortho directions. It only works using  <cursor_type> 1, "RectCursor" or 2, "RubberBand".
Is that a bug or I did anything wrong?
IMHO it is not a bug but not all combination of input_flag and cursor_type can be useful.

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Dynamic drawing and substitution of grread-function
« Reply #17 on: January 05, 2010, 02:17:24 PM »
I am wondering if there is a version that will work with 2010 and newer?

Alexander Rivilis

  • Bull Frog
  • Posts: 214
  • Programmer from Kyiv (Ukraine)
Re: Dynamic drawing and substitution of grread-function
« Reply #18 on: January 05, 2010, 08:38:36 PM »
I am wondering if there is a version that will work with 2010 and newer?
Yes! http://www.maestrogroup.com.ua/support/dyndraw.zip
DynDraw2010x32.arx for AutoCAD 2010 x86
DynDraw2010x64.arx for AutoCAD 2010 x64
But I did not tested it.

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Dynamic drawing and substitution of grread-function
« Reply #19 on: May 02, 2010, 05:21:52 PM »
Superb work Alexander, I created this using your Arx supplement, have I implemented your function correctly?

Code: [Select]
;; An example of Text Placement using a grRead substitute,
;; Function by Lee Mac, using DynDraw by Alexander Rivilis

(defun c:test ( / vers step bit v str prev obj doc point )

  (setq vers
    '((18.0 . "2010")
      (17.2 . "2009")
      (17.1 . "2008")
      (17.0 . "2007")
      (16.2 . "2006")
      (16.1 . "2005")
      (16.0 . "2004")
      (15.6 . "2002"))
  )
 
  (setq step 1e-6
        bit (if (eq "X86"
                  (strcase
                    (getenv "PROCESSOR_ARCHITECTURE")
                  )
                )
              "x32" "x64"
             )
  )

  (cond
    (
      (not
        (setq v
          (cdr
            (assoc
              (atof
                (getvar 'ACADVER)
              )
              vers
            )
          )
        )
      )
     (princ "\n** Not Compatible in this Version **")
    )
    (
      (and
        (null dyndraw)
        (not
          (arxload
            (strcat "DynDraw" v
              (if (eq "2010" v) bit "") ".arx"
            )
          )
        )
      )
     (princ "\n** Arx File not Found **")
    )
    (
      (not
        (eq ""
          (setq str
            (getstring t "\nSpecify Text String: ")
          )
        )
      )
   
      (vl-acad-defun 'UpdateTextCallBack)
     
      (setq obj
        (MCMText
          (if
            (or
              (eq AcModelSpace
                (vla-get-ActiveSpace
                  (setq doc
                    (vla-get-ActiveDocument
                      (vlax-get-acad-object)
                    )
                  )
                )
              )
              (eq :vlax-true (vla-get-MSpace doc))
            )
            (vla-get-ModelSpace doc)
            (vla-get-PaperSpace doc)
          )
          (getvar 'VIEWCTR) 0. str
        )
      )
      (setq point
        (dyndraw "UpdateTextCallBack"
          "\nSpecify Point for Text [String] : "
          "String"
          (+ 2 128 2048)
          -1
          nil
        )
      )
      (and (vl-consp point)
        (vla-put-InsertionPoint obj (vlax-3D-point point))
      )   
    )
  )
)

(defun UpdateTextCallBack ( argument / tmp )

  (cond
    (
      (eq 'STR (type argument))

      (if (eq "String" argument)
        (if
          (not
            (eq ""
              (setq tmp
                (getstring t "\nSpecify New String: ")
              )
            )
          )
          (vla-put-TextString obj tmp)
        )
        (princ "\n** Invalid Keyword **")
      )
     (setq argument t)
    )
    (
      (vl-consp argument)

      (or prev (setq prev argument))

      (if (< step (distance prev argument))
        (progn
          (setq prev argument)

          (vla-put-InsertionPoint Obj (vlax-3D-point argument))
          (vla-update obj)
        )
      )
    )
  )
  argument
)


(defun MCMText ( block point width string / o )
  (vla-put-AttachmentPoint
    (setq o
      (vla-AddMText block
        (vlax-3D-point point) width string
      )
    )
    acAttachmentPointMiddleCenter
  )
  (vla-put-InsertionPoint o
    (vlax-3D-point point)
  ) 
  o
)


Pepe

  • Newt
  • Posts: 85
Re: Dynamic drawing and substitution of grread-function
« Reply #20 on: May 04, 2010, 12:25:27 PM »
A good example, Lee Mac, thank you very much indeed...but...

Code: [Select]
(setq vers
    '((18.0 . "2010") ;no quite sure here...
      (17.2 . "2007") ;neither here...
      (17.1 . "2007")
      (17.0 . "2007")
      (16.2 . "2004")
      (16.1 . "2004")
      (16.0 . "2004")
      (15.6 . "2002"))
  )

 (Oops!...) :wink:

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Dynamic drawing and substitution of grread-function
« Reply #21 on: May 08, 2010, 10:52:10 AM »
Another example I created recently :-)



Code: [Select]
;; An example of Dynamic Slat creating using a grRead substitute,
;; Function by Lee Mac, using DynDraw by Alexander Rivilis

(defun c:slat ( / line vers step bit v n p1 p2 p3 pi/2 i prev )
  ;; Lee Mac  ~  08.05.10

  (defun line (s e)
    (entmakex
      (list
        (cons 0 "LINE")
        (cons 10 s)
        (cons 11 e)
      )
    )
  )

  (setq vers
    '((18.0 . "2010")
      (17.2 . "2009")
      (17.1 . "2008")
      (17.0 . "2007")
      (16.2 . "2006")
      (16.1 . "2005")
      (16.0 . "2004")
      (15.6 . "2002"))
  )
 
  (setq step 1e-6
        bit (if (eq "X86"
                  (strcase
                    (getenv "PROCESSOR_ARCHITECTURE")
                  )
                )
              "x32" "x64"
             )
  )

  (cond
    (
      (not
        (setq v
          (cdr
            (assoc
              (atof
                (getvar 'ACADVER)
              )
              vers
            )
          )
        )
      )
     (princ "\n** Not Compatible in this Version **")
    )
    (
      (not
        (and
          (setq n
            (getint "\nSpecify Number of Slats: ")
          )
          (setq p1
            (getpoint "\nPick First Corner Point: ")
          )
        )
      )
      (princ "\n*Cancel*")
    )
    (
      (and
        (null dyndraw)
        (not
          (arxload
            (strcat "DynDraw" v
              (if (eq "2010" v) bit "") ".arx"
            )
          )
        )
      )
     (princ "\n** Arx File not Found **")
    )
    (   
      (vl-acad-defun 'UpdateSlatCallBack)
     
      (setq p2
        (dyndraw "UpdateSlatCallBack"
          "\nPick Second Point [Number] : "
          "Number"
          (+ 1 2 128 2048)
          -1
          nil
        )
      )
     
      (redraw)
     
      (if (vl-consp p2)
        (progn
          (setq i (/ (- (cadr p2) (cadr p1)) n)
             pi/2 (/ pi 2.) p3 (cons (car p2) (cdr p1)))
          (
            (lambda ( j )
              (repeat (1- n)
                (apply (function line)
                  (mapcar
                    (function
                      (lambda ( point )
                        (trans point 1 0)
                      )
                    )
                    (list
                      (polar p1 pi/2 (* (setq j (1+ j)) i))
                      (polar p3 pi/2 (* j i))
                    )
                  )
                )
              )
            )
            0
          )
        )
      )
    )
  )
  (princ)
)

(defun UpdateSlatCallBack ( argument / tmp )

  (cond
    (
      (eq 'STR (type argument))

      (redraw)

      (if (eq "Number" argument)
        (if
          (setq tmp
            (getint "\nSpecify Number of Slats: ")
          )
          (setq n tmp)
        )
        (princ "\n** Invalid Keyword **")
      )
     (setq argument t)
    )
    (
      (vl-consp argument)

      (or prev (setq prev argument))

      (if (< step (distance prev argument))
        (progn
          (setq prev argument p2 argument)

          (setq i    (/ (- (cadr p2) (cadr p1)) n)
                pi/2 (/ pi 2.)
                p3   (cons (car p2) (cdr p1))
                p4   (cons (car p1) (cdr p2)))

          (redraw)
          (grvecs (cons -3 (list p1 p3 p3 p2 p1 p4 p4 p2)))
         
          (
            (lambda ( j )
              (repeat (1- n)
                (grvecs
                  (cons -30
                    (list (polar p1 pi/2 (* (setq j (1+ j)) i))
                          (polar p3 pi/2 (* j i))
                    )
                  )
                )
              )
            )
            0
          )
        )
      )
    )
  )
  argument
)

I really like this function :-)

qjchen

  • Bull Frog
  • Posts: 285
  • Best wishes to all
Re: Dynamic drawing and substitution of grread-function
« Reply #22 on: July 21, 2010, 10:18:23 PM »
Thank you very much, Alexander
and thank you Lee Mac too :)

After reading through your example, now I can write a such function that I always search for:

Find the perpendicular line to a curve through a point on the curve by grread like method.

Code: [Select]
;;; Thanks great to  Alexander Rivilis very very much
;;; and thanks to Lee Mac too
;;; http://www.theswamp.org/index.php?topic=9133.0
;;; by qjchen@gmail.com
;;; Find the perpendicular line to a curve through a point on the curve.
(defun C:test ( / curve-obj ent p)
  (if (null dyndraw) (progn (arxload "dyndraw.arx")))
  (prompt "\n Please select a curve first:")
  (setq curve-obj (vlax-ename->vla-object (car (entsel))))
  (vl-acad-defun 'dyn_call_back)
  (setq p (dyndraw "dyn_call_back" "\nPlease select a point: " "Number" 0 -1 nil))        
   (if (= (type p) 'LIST) (myfun p))
   (redraw)
  (princ)
)

(defun dyn_call_back (p)
  (mygrdraw p)
  p
)

(defun mygrdraw(p / p1)
  (redraw)
  (setq p1 (vlax-curve-getClosestPointTo curve-obj p))
  (grdraw p1 (polar p1 (+ (/ pi 2) (angle (list 0 0 0) (vlax-curve-getFirstDeriv curve-obj (vlax-curve-getParamAtPoint curve-obj (vlax-curve-getClosestPointTo curve-obj p))))) (* 0.3 (getvar "viewsize"))) 2)
)

(defun myfun(p)
 (entmakeline1 p (polar p (+ (/ pi 2) (angle (list 0 0 0) (vlax-curve-getFirstDeriv curve-obj (vlax-curve-getParamAtPoint curve-obj p)))) (* 0.3 (getvar "viewsize"))))
)


;;entmake line
(defun entmakeline1 (pt1 pt2)
  (if (> (distance pt1 pt2) 1e-5)
    (entmake (list (cons 0 "LINE")(cons 6 "BYLAYER") (cons 10 pt1) (cons 11 pt2) ))
  )
  (princ)
)

« Last Edit: July 21, 2010, 10:53:02 PM by qjchen »
http://qjchen.mjtd.com
My blog http://chenqj.blogspot.com (Chinese, can be translate into English)

cjw

  • Guest
Re: Dynamic drawing and substitution of grread-function
« Reply #23 on: July 23, 2010, 02:32:57 AM »
Thank you very much, Alexander.
I am waiting the substitution of grread-function for very long time.  :-D

Can anybody tell me what's wrong with the code under.

(defun C:TT (/ LOOP P)
  (vl-acad-defun 'CALL-BACK)
  (setq LOOP t)
  (while LOOP
    (setq P (dyndraw
         "CALL-BACK"
         "TEST..."
         "B"
         (+ 2 128 2048)
         0
         NIL
       )
    )
    (and (= (type P) 'list) (setq LOOP NIL))
  )
)


;; It work, but slowly.
(defun CALL-BACK (ARG)
  (command "._POINT" "_NON" ARG)
)

;; It can't work.
(defun CALL-BACK (ARG)
  (entmake (list (cons 0 "POINT")
       (cons 100 "AcDbEntity")
       (cons 8 "0")
       (cons 100 "AcDbPoint")
       (cons 10 ARG)
      )
  )
)



And How to "Dynamic" move SelectionSet with ssget.

(setq SS (ssget))

(command "._MOVE" SS "" "_NON" PT1 "_NON" PT2)



Hugo

  • Bull Frog
  • Posts: 422
Re: Dynamic drawing and substitution of grread-function
« Reply #24 on: March 28, 2012, 01:37:18 AM »
dyndraw will no longer run on Autocad2013   :-( :-(


dyndraw läuft auf Autocad2013 nicht mehr

Alexander Rivilis

  • Bull Frog
  • Posts: 214
  • Programmer from Kyiv (Ukraine)
Re: Dynamic drawing and substitution of grread-function
« Reply #25 on: March 28, 2012, 01:56:20 AM »
dyndraw will no longer run on Autocad2013   :-( :-(


dyndraw läuft auf Autocad2013 nicht mehr

Are you sure?  :-) Try to download last version.

Hugo

  • Bull Frog
  • Posts: 422
Re: Dynamic drawing and substitution of grread-function
« Reply #26 on: March 28, 2012, 02:10:38 AM »
Thank you again, it works now.   ^-^ ^-^

Danke jetzt funktioniert es wieder.

reltro

  • Guest
Re: Dynamic drawing and substitution of grread-function
« Reply #27 on: June 25, 2012, 12:38:43 PM »
Hello,
I wrote a lil workround for DynDraw, but I have a Problem:
When I Pan with the MiddleMouseButton Autocad chrases in Fatal Way...

U may can give me a an answer about this, i don't know, bug?

I'm working with acad2012 and 2013...
I have tried the examples above, from LeeMac -> same Problem, so i don't think its a problem of my workaround...

[EDIT]
A UserBreak with {ESC} -> fires every time an error,wich is displayed, but not cancel dyndraw with 'nil
Why This?


hope for help
lg reltro

Ps.: 2 .lsp-files in the Attachment
« Last Edit: June 25, 2012, 07:06:31 PM by reltro »

martinle

  • Newt
  • Posts: 22
Re: Dynamic drawing and substitution of grread-function
« Reply #28 on: June 27, 2012, 12:22:13 AM »
Another example I created recently :-)



Code: [Select]
;; An example of Dynamic Slat creating using a grRead substitute,
;; Function by Lee Mac, using DynDraw by Alexander Rivilis

(defun c:slat ( / line vers step bit v n p1 p2 p3 pi/2 i prev )
  ;; Lee Mac  ~  08.05.10

  (defun line (s e)
    (entmakex
      (list
        (cons 0 "LINE")
        (cons 10 s)
        (cons 11 e)
      )
    )
  )

  (setq vers
    '((18.0 . "2010")
      (17.2 . "2009")
      (17.1 . "2008")
      (17.0 . "2007")
      (16.2 . "2006")
      (16.1 . "2005")
      (16.0 . "2004")
      (15.6 . "2002"))
  )
 
  (setq step 1e-6
        bit (if (eq "X86"
                  (strcase
                    (getenv "PROCESSOR_ARCHITECTURE")
                  )
                )
              "x32" "x64"
             )
  )

  (cond
    (
      (not
        (setq v
          (cdr
            (assoc
              (atof
                (getvar 'ACADVER)
              )
              vers
            )
          )
        )
      )
     (princ "\n** Not Compatible in this Version **")
    )
    (
      (not
        (and
          (setq n
            (getint "\nSpecify Number of Slats: ")
          )
          (setq p1
            (getpoint "\nPick First Corner Point: ")
          )
        )
      )
      (princ "\n*Cancel*")
    )
    (
      (and
        (null dyndraw)
        (not
          (arxload
            (strcat "DynDraw" v
              (if (eq "2010" v) bit "") ".arx"
            )
          )
        )
      )
     (princ "\n** Arx File not Found **")
    )
    (   
      (vl-acad-defun 'UpdateSlatCallBack)
     
      (setq p2
        (dyndraw "UpdateSlatCallBack"
          "\nPick Second Point [Number] : "
          "Number"
          (+ 1 2 128 2048)
          -1
          nil
        )
      )
     
      (redraw)
     
      (if (vl-consp p2)
        (progn
          (setq i (/ (- (cadr p2) (cadr p1)) n)
             pi/2 (/ pi 2.) p3 (cons (car p2) (cdr p1)))
          (
            (lambda ( j )
              (repeat (1- n)
                (apply (function line)
                  (mapcar
                    (function
                      (lambda ( point )
                        (trans point 1 0)
                      )
                    )
                    (list
                      (polar p1 pi/2 (* (setq j (1+ j)) i))
                      (polar p3 pi/2 (* j i))
                    )
                  )
                )
              )
            )
            0
          )
        )
      )
    )
  )
  (princ)
)

(defun UpdateSlatCallBack ( argument / tmp )

  (cond
    (
      (eq 'STR (type argument))

      (redraw)

      (if (eq "Number" argument)
        (if
          (setq tmp
            (getint "\nSpecify Number of Slats: ")
          )
          (setq n tmp)
        )
        (princ "\n** Invalid Keyword **")
      )
     (setq argument t)
    )
    (
      (vl-consp argument)

      (or prev (setq prev argument))

      (if (< step (distance prev argument))
        (progn
          (setq prev argument p2 argument)

          (setq i    (/ (- (cadr p2) (cadr p1)) n)
                pi/2 (/ pi 2.)
                p3   (cons (car p2) (cdr p1))
                p4   (cons (car p1) (cdr p2)))

          (redraw)
          (grvecs (cons -3 (list p1 p3 p3 p2 p1 p4 p4 p2)))
         
          (
            (lambda ( j )
              (repeat (1- n)
                (grvecs
                  (cons -30
                    (list (polar p1 pi/2 (* (setq j (1+ j)) i))
                          (polar p3 pi/2 (* j i))
                    )
                  )
                )
              )
            )
            0
          )
        )
      )
    )
  )
  argument
)

I really like this function :-)


Her lee Hello!

slat.lsp looks great. It is not bit on acad 2012 64th Would it be possible that it will work on this version?

Best regards Martin
sorry for my english

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Dynamic drawing and substitution of grread-function
« Reply #29 on: June 27, 2012, 04:49:56 AM »
Hi Martin,

If there is a dyndraw.arx version available for AutoCAD 2012 64-bit, then yes, I'm sure that my code could be manipulated to work in this version.

Lee