Trimming lines under dynamic block

Trimming lines under dynamic block

dlbsurveysuk
Collaborator Collaborator
49 Views
2 Replies
Message 1 of 3

Trimming lines under dynamic block

dlbsurveysuk
Collaborator
Collaborator

Hi, I've got the following code that makes use of Lee mac's "Set Dynamic Block Property Value" routine to insert a dynamic block between two parallel lines using 3 picks to specify the insertion point, rotation+length, and width.

 

The first problem is that quite often one side of the block is not exactly over the line below (even though I've snapped perpendicular to it). I noticed this because the line below can't be trimmed out below the block.

I've discovered that if I include a vla-sendcommand to FLATTEN the block after insertion it will then be perfectly over the line which now becomes trimmable.

 

Solving the first problem causes a second problem - the dynamic block loses it's grips and is no longer adjustable.

 

Any ideas? (dynamic block attached)

Thanks.

 

;; 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)
    )
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(defun c:WIN (/ *error* osm normal pt1 pt2 pt3 d w o)

         (defun *error* (MSG)
            (if (/= MSG "Function cancelled")
                (princ (strcat "\nError: " MSG)))
              (if osm (setvar 'osmode OSM))
          (princ) )

(vl-load-com)
(setq OSM (getvar 'osmode))
(setq NORMAL (trans '(0.0 0.0 1.0) 2 0 T))

(setvar 'osmode 512)
  (setq PT1 (getpoint "\nInsertion point: "))
  (setq PT2 (getpoint PT1 "\nRotation and length: "))
(setvar 'osmode 128)
  (setq PT3 (getpoint PT2 "\nWidth: "))
(setvar 'osmode 0)

(entmake
      (list
           '(0 . "INSERT") '(8 . "WINDOW") '(2 .  "fulldw") (cons 10 (trans PT1 1 0))
           (cons 50 (+ (angle PT1 PT2) (angle '(0.0 0.0 0.0) (trans '(1.0 0.0 0.0) 2 NORMAL T))))
            (cons 41 1) (cons 42 1) (cons 43 1)
      )
)

	(setq o (vlax-ename->vla-object (entlast)))

	(setq d (distance PT1 PT2))
	(setq w (distance PT2 PT3))

    (LM:setdynpropvalue o "Length Stretch" (rtos d 2 3))
    (LM:setdynpropvalue o "Distance3" (rtos w 2 3))

(setvar 'osmode OSM)

(vla-Sendcommand (vla-Get-ActiveDocument (vlax-Get-Acad-Object)) "_FLATTEN\r_L\r\r\r")
(vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) "WIN ")

(princ)
)

 

0 Likes
50 Views
2 Replies
Replies (2)
Message 2 of 3

dlbsurveysuk
Collaborator
Collaborator

Was thinking maybe the block isn't perfect in some way, but if not, why is it fine a lot of the time?

 

Also, I forgot to mention that if I don't flatten the block I can zoom in, grab the dynamic grip and re snap perpendicular, which also corrects things. 

0 Likes
Message 3 of 3

dlbsurveysuk
Collaborator
Collaborator

Or maybe it's something to do with the precision of (setq w (distance PT2 PT3)) and (LM:setdynpropvalue o "Distance3" (rtos w 2 3)) ?

0 Likes