Jump to content

Rotate selected blocks to nearest line


Ohnoto

Recommended Posts

I'm trying to get a selected list of blocks to rotate to the nearest line. What I'm not sure of is getting the angle of the insertion point to nearest road lines (See Code).

 

Then, with some of the blocks we have they are usually at 90, 180, or 270 degrees of the road lines, so a syntax would be needed so I could specify which blocks and what angle value to add to it. And then fill in this value for the "Block Angle" property.

 

Below is a bit of code I do have, I'm just not sure how to get it in order and then to get the angle value.

 

Thanks!

 

Road Lines

(setq baseline
        (ssget "_X"
         (list
           (cons 0 "ARC,CIRCLE,ELLIPSE,LINE,*POLYLINE,SPLINE")
           (cons 8 "GPS-ROAD,BASELINE,EOG,EOP,FOGLINE,FOC"))))

Syntax Example

;;;---Syntax---     Block Name          Angle
(AngleFunction    "handhole-sta"        270)

Insert Value

(if (setq ss (ssget "_:L"
                     (list '(0 . "INSERT")
                           (cons 2
                                 (apply (function strcat)
                                        (cons "`*U*,"
                                              (mapcar (function (lambda (s) (strcat s ",")))
                                                      blocks)))))))
        (progn
     (vlax-for x (setq ss (vla-get-activeselectionset
                            (cond (*ACADdoc*)
                                  ((setq *ACADdoc* (vla-get-activedocument
                                                     (vlax-get-acad-object)))))))
       (if (and (vl-position
                  (strcase (vlax-get-property
                             x
                             (if (vlax-property-available-p x 'EffectiveName)
                               'EffectiveName
                               'Name)))
                  blocks)
                (eq (vla-get-isDynamicBlock x) :vlax-true))
         (vl-some (function (lambda (p)
                              (if (eq (vlax-get-property p "PropertyName") "Block Angle")
                                (not (vl-catch-all-error-p
                                       (vl-catch-all-apply
                                         (function vlax-put-property)
                                         (list p "Value" myAngle)))))))                ; Assigns value of the angle to the property
                  (vlax-invoke x 'GetDynamicBlockProperties))))
     (vla-delete ss)))

Link to comment
Share on other sites

  • 3 weeks later...

I had exactly the same need a few years back.

Fatty solved it for me in the following link.

 

http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Automatically-orientating-blocks-parallel-or-perpendicular-to/m-p/1421015/highlight/true

 

I hope I do not upset anyone by linking to an external site.

But I did not want to take credit for someone elses work.

 

Hope this helps you

Link to comment
Share on other sites

Yep! Those vlax-curve functions are exactly what you're after!

 

What I'd suggest in your case is stepping through your baseline selection set for each insertion point. Then use the vlax-curve-getClosestPointTo and see which has the shortest distance from the insertion point. Then use the vlax-curve-getFirstDeriv to obtain the direction at that point (tip: it gives a 3d point vector showing a direction from 0,0,0. So you can obtain the angle from X-axis through a call to angle from 0,0,0 to the vector-point. If you want an angle towards Z as well, then you'd probably need to fiddle a bit with cdr and / or reverse.)

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...