Insert dynamic block between 2 points

Insert dynamic block between 2 points

Anonymous
Not applicable
2,468 Views
10 Replies
Message 1 of 11

Insert dynamic block between 2 points

Anonymous
Not applicable

Hi forum,

 

I have a dynamic block(see block 'inspection - member rating' block in attached template file. I use this to illustrate inspection data of steel members shown on a pdf drawing xref. I also use the completed inspection drawing to extract the data into excel.


The block mainly consists of a line with an equal stretch parameter on either end. Currently I have to enter the block at the center of the member i want to markup  and then stretch the line to the extents of the member. I would like some direction into being able (perhaps through lisp?) to click between the two points  where I want the block to be placed(either end of member).

 

Also, (if you happen to be having a good day)  the block contains a few fields, I would like the layer of the block to change automatically based on the value entered in the 'rating' field of the block. (layers are color coded based on rating of member)

 

 

Finally,(if you're having an even better day) it would be great if I can use this on a tablet  in the field, is there anyway to change the interface of field entry to something that is more touch-friendly (perhaps a dialogue box with buttons or radio buttons to pick validated entries for the block)

 

By all means not expecting the complete solution handed over but any pointers would be very helpful.

 

Thanks in advance 

 

 

0 Likes
2,469 Views
10 Replies
Replies (10)
Message 2 of 11

doglips
Advocate
Advocate

This should get you your insertion point.

(setq p1 (getpoint "\nSelect First Point:"))
(setq p2 (getpoint "\nSelect Second Point:"))
(setq BlkInsPt (polar p1 (angle p1 p2) (/ (distance p1 p2)2)))

 

I'm not clear on what you want for the layer/rating thing.

Please a little more detail

Message 3 of 11

Kent1Cooper
Consultant
Consultant

For the subject-line part, no code is necessary, because [unless you have a pretty old version that pre-dates this] there's a mid-of-2 Object Snap mode.  You can't set it to be running all the time as you can ENDpoint or INTersection, but [by default, if you haven't changed related settings] either Ctrl+right-click or Shift+right-click calls up the Osnap modes list, which you can do when it's asking for the insertion point, and pick Mid Between 2 Points, near the top.  Or you can type in either M2P or MTP just as you would type in END to Snap to an endpoint.

Kent Cooper, AIA
0 Likes
Message 4 of 11

Anonymous
Not applicable

Thanks for the 1st tip.

 

Regarding Layers, I would like the layer of the object to change automatically  according to the value I enter in one of the block fields. 

0 Likes
Message 5 of 11

Anonymous
Not applicable

Thank you for your response. You suggestion will place the block in between the 2 points but the specific block has a line in it that needs to be stretched between the 2 points that i initially select. I was hoping that that line can get automatically stretched between the 2 points

0 Likes
Message 6 of 11

steve_carson
Enthusiast
Enthusiast

Lee Mac has some great functions for dealing with dynamic blocks here:

 

http://www.lee-mac.com/dynamicblockfunctions.html

 

Those, coupled with what doglips posted should get you most of the way there. The layer part of your request is tricky though. I think to make it work the way you want you would have to add the attribute filling part of the process to the function as opposed to the normal way of filling in attributes. Lee has plenty of attribute functions too, dig around his site.

 

A small comment on your dynamic block, I would make the Rotate Parameter and grip part of the Move actions selection set so the grip moves with the tag. It's a little cleaner that way.

Message 7 of 11

alanjt_
Collaborator
Collaborator

I would avoid polar in this instance. If the points have elevations, or the ucs is rotated, it will alter polar results.

 

Try this instead:

(defun _midPoint (p1 p2)
  (mapcar (function (lambda (a b) (/ (+ a b) 2.))) p1 p2)
)

 

0 Likes
Message 8 of 11

SeeMSixty7
Advisor
Advisor

I agree that if contending with 3D points and Elevations you need to consider the actual 3D MIDPOINT. For this type of insert, I believe the intent is for the lines to be aligned to the current UCS. I don't think Polar would be the culprit in this instance. It would be the distance formula, that creates the issue. Since it works on the distance between the 3D points and not just the flat (XY) portions of the point. Polar will return the point based on the current UCS and the correct points based on the correct input. Your method handles the actual 3D Midpoint well. If the points are not aligned with the current UCS, the choice needs to be made if the insert should take place on the elevation of first point, second point or as your function returns the actual midpoint. Then of course there is yet another option of aligning the current UCS along the two points and then inserting the block aligned. I would doubt that is the case though. Looks like the OP has a few options to consider.

0 Likes
Message 9 of 11

Kent1Cooper
Consultant
Consultant

A slightly-shorter-code approach that I have used, if one doesn't have a new-enough version to have M2P / MTP Osnap:

 

(defun m2 (p1 p2)
  (mapcar '/ (mapcar '+ p1 p2) '(2 2 2))
)
Kent Cooper, AIA
0 Likes
Message 10 of 11

alanjt_
Collaborator
Collaborator

@Kent1Cooper wrote:

A slightly-shorter-code approach that I have used, if one doesn't have a new-enough version to have M2P / MTP Osnap:

 

(defun m2 (p1 p2)
  (mapcar '/ (mapcar '+ p1 p2) '(2 2 2))
)

While we are talking about fractions of seconds in this situation, your contribution runs through the list twice.

We're splitting two points, so it's not a big deal, but it's bad practice for other, much larger list iterations.

 

Command: (benchmark '( (_midPoint p1 p2) (m2 p1 p2) ))
Elapsed milliseconds / relative speed for 32768 iteration(s):
    (_MIDPOINT P1 P2).....1014 / 1.01 <fastest>
    (M2 P1 P2)............1029 / 1 <slowest>

Also, you are forcing cad to divide a real (x, y, z from point) by an integer. Generally not a big deal, but why create additional work for the computer?

0 Likes
Message 11 of 11

Kent1Cooper
Consultant
Consultant

alanjt_ wrote:

.... you are forcing cad to divide a real ... by an integer. .... why create additional work for the computer?

Interesting notion -- I've never encountered the concept that it's "additional work" for it to divide a real number by an integer rather than by another real number.  Can you explain why?  If decimals are added after the 2's in my divisor list, does the all-of-1% speed "disadvantage" improve?

Kent Cooper, AIA
0 Likes