Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Dynamic Block Insert and use lisp to modify Parameter

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
akshay.thakker
6595 Views, 5 Replies

Dynamic Block Insert and use lisp to modify Parameter

Hi

 

I have a simple dynamic block for a break line with one dynamic parameter called "length". I want to use this inside a lisp routine which allows me to do the following

 

  1. Select pt1,
  2. Select pt2,
  3. Show the block insert dialog, so I can manually scale the size of the break point inside the screen (with the help of my mouse)
  4. nsert the block using the following parameters
  5. insertion point, (mid point between pt1 & pt2)
  6. scale (use the scale as per point 3)
  7. angle (angle between pt1 & pt2)
  8. The lenght dynamic parameter = distance betwen pt1& pt2

While I am able to create a lisp routine to draw break line by manually asking for size of break, I would like to do it in a way that I can visually size the break point by using the dynamic block. I have also included that lisp routine along with the block for the dynamic break point.

 

I can insert the dynamic block using the parameters from 5 to 7 but dont know how to modify the lenght parameter from within a lisp routine.

 

Please help

 

Thanks

 

5 REPLIES 5
Message 2 of 6

bump. nobody can help? Cat Sad

Message 3 of 6
Lee_Mac
in reply to: akshay.thakker

Try the following code akshay:

 

(defun c:brkline ( / *error* blk bln dwg obj pt1 pt2 val var )

    (defun *error* ( msg )
        (mapcar 'setvar var val)
        (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")))
            (princ (strcat "\nError: " msg))
        )
        (princ)
    )
    
    (setq bln  "BRKLINE"
          var '(cmdecho attreq)
          val  (mapcar 'getvar var)
    )
    (mapcar 'setvar var '(0 0))
    (cond
        (   (not
                (or (tblsearch "block" (setq blk bln))
                    (and (setq dwg (findfile (strcat bln ".dwg")))
                         (progn
                             (command "_.-insert" dwg nil)
                             (tblsearch "block" (setq blk bln))
                         )
                    )
                )
            )
            (princ (strcat "\nBlock \"" bln "\" not found."))
        )
        (   (and (setq pt1 (getpoint "\nSpecify 1st point: "))
                 (setq pt2 (getpoint "\nSpecify 2nd point: " pt1))
            )
            (prompt "\nSpecify scale factor: ")
            (initcommandversion)
            (if
                (and
                    (vl-cmdf
                        "_.-insert" blk
                        "_r"   (* 180.0 (/ (angle pt1 pt2) pi))
                        "_non" (mapcar '(lambda ( a b ) (/ (+ a b) 2.0)) pt1 pt2) "\\"
                    )
                    (setq obj (entlast))
                    (setq obj (vlax-ename->vla-object obj))
                    (= "AcDbBlockReference" (vla-get-objectname obj))
                    (= :vlax-true (vla-get-isdynamicblock obj))
                )
                (LM:setdynpropvalue obj "length" (distance pt1 pt2))
            )
        )
    )
    (*error* nil) (princ)
)

;; Set Dynamic Block Property Value  -  Lee Mac
;; Modifies the value of a Dynamic Block property (if present)
;; blk - [vla] VLA Dynamic Block Reference object
;; prp - [str] Dynamic Block property name (case-insensitive)
;; val - [any] New value for property
;; Returns: [any] New value if successful, else nil

(defun LM:setdynpropvalue ( blk prp val )
    (setq prp (strcase prp))
    (vl-some
       '(lambda ( x )
            (if (= prp (strcase (vla-get-propertyname x)))
                (progn
                    (vla-put-value x (vlax-make-variant val (vlax-variant-type (vla-get-value x))))
                    (cond (val) (t))
                )
            )
        )
        (vlax-invoke blk 'getdynamicblockproperties)
    )
)

(vl-load-com) (princ)

 

The Set Dynamic Block Property Value function is part of my set of Dynamic Block Functions.

 

Lee

Message 4 of 6
akshay.thakker
in reply to: Lee_Mac

Hi Lee_Mac:

 

Thank you so much for taking the time to prepare this routine for me. I am highly obliged.

 

I was initially getting an error because i had saved the dynamic block inside another drawing but sorted it out once I saved the block definition as a drawing file.

 

For others wanting to use this routine, I have attached the dynamic block reference brkline.dwg that they can make part of their library with this message. You may have to rename brkline to another name if you have express tools installed as the tools also contain a dwg named brkline which can cause some errors.

 

 

 

 

 

Message 5 of 6
Lee_Mac
in reply to: akshay.thakker

akshay.thakker wrote:

Thank you so much for taking the time to prepare this routine for me. I am highly obliged.

 

You're most welcome akshay, I'm pleased that the program is working well for you & I appreciate your gratitude.

 

Lee

Message 6 of 6

As always Lee Mac's routines are awesome! Sorry for some grammar error because I do not speak English, I use the google translator.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost