Jump to content

Block showing distance with arrow pointing in correct direction?


Akeane

Recommended Posts

So the problem im having is i have code that runs to show the offset of measured points to design points, unfortunately the code works by inserting one of 4 predefined blocks for NSEW, or one of 4 when in 2 directions; only showing orthogonal distances. These work by passing through the distance to the block tag, and then comparing the EW, and/or NS values to determine the correct arrow direction to insert the correct block.

What i want is instead of using orthogonal distances, is to have an arrow block within these blocks, that changes the direction of the arrow, based on a bearing that you pass through.
eg if the horizontal distance between 2 points is 25mm at a bearing of 45 degrees, then a tag is created as per normal with 25 and an arrow point 45 degrees.

Any good ideas? I've looked in the forums and couldn't find anything to solve this. Attached is an image of what i have currently made, note the aligned one showing 130mm is kinda what i want, but that arrow is not dynamic, it just goes left or right and the whole block is just rotated to show the bearing. It makes for a messy plan and a lot of neck craning to present to a client
6ZCoPzn.png
 

Link to comment
Share on other sites

Assuming that I've correctly understood what you are looking to achieve, you could define a basic dynamic attributed block containing a single attribute to display the distance, and a rotation parameter with a rotate action assigned to the arrow symbol within the block. Then, you can use a program to automatically insert the block, populate the attribute, and configure the dynamic block parameter appropriately:

 

bearingblock.gif.e94d54b466e37df013acd6367e66bbc2.gif

 

To offer an example to demonstrate this in action, try using the following code in conjunction with the attached dynamic block:

(defun c:bb ( / ang blk bln dis ins obj pt1 pt2 scl )

    (setq bln "TEST" ;; Block name
          dis "DIS"  ;; Distance attribute tag
          ang "ANG"  ;; Rotation parameter name
          scl 1.0    ;; Block scale
    )
    (cond
        (   (not (setq blk (LM:importblock bln)))
            (princ (strcat "\nThe block \"" bln "\" was not found or could not be defined."))
        )
        (   (and (setq pt1 (getpoint "\nSpecify 1st point of bearing: "))
                 (setq pt2 (getpoint "\nSpecify 2nd point of bearing: " pt1))
                 (setq ins (getpoint "\nSpecify block insertion point: "))
            )
            (setq obj
                (vla-insertblock
                    (vlax-get-property
                        (vla-get-activedocument (vlax-get-acad-object))
                        (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace)
                    )
                    (vlax-3D-point (trans ins 1 0))
                    blk
                    scl scl scl
                    (angle '(0 0) (trans (getvar 'ucsxdir) 0 (trans '(0 0 1) 1 0 t) t)) 
                )
            )
            (LM:vl-setattributevalue obj dis (rtos (distance pt1 pt2) 2 0))
            (LM:setdynpropvalue obj ang (angle pt1 pt2))
        )
    )
    (princ)
)

;; Set Attribute Value  -  Lee Mac
;; Sets the value of the first attribute with the given tag found within the block, if present.
;; blk - [vla] VLA Block Reference Object
;; tag - [str] Attribute TagString
;; val - [str] Attribute Value
;; Returns: [str] Attribute value if successful, else nil.

(defun LM:vl-setattributevalue ( blk tag val )
    (setq tag (strcase tag))
    (vl-some
       '(lambda ( att )
            (if (= tag (strcase (vla-get-tagstring att)))
                (progn (vla-put-textstring att val) val)
            )
        )
        (vlax-invoke blk 'getattributes)
    )
)

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

;; Import Block Definition  -  Lee Mac
;; blk - [str] Block name, drawing filename, or full filepath
;; Returns: [str] Block name if successful, else nil

(defun LM:importblock ( blk / bse cmd ext pth )
    (setq pth (vl-string-translate "/" "\\" (vl-filename-directory blk)) 
          ext (cond ((vl-filename-extension blk)) (".dwg"))
          bse (vl-filename-base blk)
    )
    (if (not (or (= "" pth) (wcmatch pth "*\\")))
        (setq pth (strcat pth "\\"))
    )
    (cond
        (   (tblsearch "block" bse) bse)
        (   (setq blk (findfile (strcat pth bse ext)))
            (setq cmd (getvar 'cmdecho))
            (setvar 'cmdecho 0)
            (command "_.-insert" blk nil)
            (setvar 'cmdecho cmd)
            (if (tblsearch "block" bse)
                bse
            )
        )
    )
)

(vl-load-com) (princ)

The above uses existing functions from my Attribute Function library and Dynamic Block Function library.

test.dwg

  • Like 1
Link to comment
Share on other sites

Hey the Lee Mac! I've used some of your codes and tutorials from your website. 

Really appreciate you taking the time to write all this, this is exactly what i was looking for.
It looks like i have a lot to learn about working with dynamic blocks, and this has been an incredibly helpful starting point.

I also am not at all familiar with the use of VLA functions, so l was really intrigued by your use in property definition and block insertion. In searching for more info i actually found a helpful post from 2008 😉

Thanks again, this has been a good example of what i can be doing with Lisp
 

Link to comment
Share on other sites

  • 11 months later...
On 12/1/2019 at 5:44 AM, Lee Mac said:

Assuming that I've correctly understood what you are looking to achieve, you could define a basic dynamic attributed block containing a single attribute to display the distance, and a rotation parameter with a rotate action assigned to the arrow symbol within the block. Then, you can use a program to automatically insert the block, populate the attribute, and configure the dynamic block parameter appropriately:

 

bearingblock.gif.e94d54b466e37df013acd6367e66bbc2.gif

 

To offer an example to demonstrate this in action, try using the following code in conjunction with the attached dynamic block:

 

 

Hey Lee, ive since moved on from this and started using leaders instead with a block instead. You use the vl insert block, but is there anyway to incorporate this into the mleader functionality? or is the only way to create a new dynamic block leader?

Cheers

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...