Jump to content

Block Distance From Nearest Point on a Polyline


wannabe

Recommended Posts

Opps! How mach new listings. Ok Lee Mac. Coordinates, tables and so on is good training. :)

 

I try :P

 

I didn't think I could make it so that the info was in the drawing, but then I improved it and improved it till I could...

Link to comment
Share on other sites

  • Replies 65
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    33

  • wannabe

    16

  • ASMI

    8

  • SEANT

    5

Top Posters In This Topic

Posted Images

Lee, a great effort, that encompasses all of my requirements.......almost:) .

 

The output value takes into consideration depths when working out the minimum distance for each block. But, the problem is, we need to ignore all the Z coords.

 

One option would be for me to copy the drawing, flatten the lot and then run your command - which, if is the only option available, then still reduces the duration in comparison to the original method considerably. So I take my hat off now and thank you already.

 

But, if you fancy the challenge, and want the pleasure of marrying all 5 of my sisters, then is there any chance you could somehow adjust to suit my ultimate requirements?

 

Also, I showed the engineer the beta version and he then asked if we could somehow flag which side of the track the block is on.

 

I've attached a copy of the drawing showing the difference between a 2d line and the corresponding distance output from the lisp.

 

Cheers.

Link to comment
Share on other sites

This should sort your Z coord issue:

 

(defun c:pdis (/ oldlay cCurve cBlock txtpnt index ent dPt1 dPt2 blkDist blklist txt)

   (defun makelay (x)
   (if (not (tblsearch "Layer" x))
       (progn
       (setvar "cmdecho" 0)
       (command "-layer" "m" x "")
       (setvar "cmdecho" 1)
       ) ;_  end progn
       (setvar "CLAYER" x)
   ) ;_  end if
   ) ;_  end defun

   (defun Make_Text (txt_pt txt_val)
   (entmake
       (list '(0 . "TEXT")
         '(8 . "TEXT")
         (cons 10 txt_pt)
         (cons 40 2.5)
         (cons 1 txt_val)
         '(50 . 0.0)
         '(7 . "STANDARD")
         '(71 . 0)
         '(72 . 0)
         '(73 . 0)
       ) ; end list
   ) ; end entmake
   ) ;_  end defun

   (vl-load-com)
   (setq oldlay (getvar "clayer"))
   (if
   (and
       (setq cCurve (entsel "\nSelect curve to measure > "))
       (member (cdr (assoc 0 (entget (car cCurve))))
           '("LINE" "POLYLINE" "LWPOLYLINE" "SPLINE" "ARC" "CIRCLE" "ELLIPSE")
       ) ;_  end member
   ) ; end and
      (progn
          (while
          (and
              (setq cBlock (ssget '((0 . "INSERT"))))
              (setq txtpnt (getpoint "\nSelect Point for Table > "))
          ) ;_  end and
             (makelay "TEXT")
             (setq index   (1- (sslength cBlock))
               blklist "\n"
               txt        1
             ) ;_  end setq
             (while (not (minusp index))
             (setq    ent    (entget (ssname cBlock index))
               dPt1    (cdr (assoc 10 ent))
               dPt2    (vlax-curve-getClosestPointTo (car cCurve) dPt1)
               blkDist    (expt (+ (expt (- (car dPt1) (car dPt2)) 2)
                        (expt (- (cadr dPt1) (cadr dPt2)) 2)
                         ) ;_  end +
                         0.5
                   ) ;_  end exp
             ) ;_  end setq
             (setq    blklist    (strcat    (rtos (car dPt1) 2 1)
                       ","
                       (rtos (cadr dPt1) 2 1)
                       "   <--->   "
                       (rtos blkDist 2 1)
                   ) ;_  end strcat
             ) ;_  end setq
             (Make_Text (polar txtpnt (* pi 1.5) (* 3.5 txt)) blklist)
             (setq    index (1- index)
               txt   (1+ txt)
             ) ;_  end setq
             ) ; end while
          ) ;_  end while
      ) ;_  end progn
      (princ "\n<!> Empty selection or this isn't a Curve (line, polyline, etc.) <!> ")
   ) ; end if
   (setvar "clayer" oldlay)
   (princ)
) ;_  end defun

Link to comment
Share on other sites

I notice that the text in your supplied drawing is a lot smaller than my code produces.

 

I can changed the text element in my code to suit your specs if you wish?

Link to comment
Share on other sites

I notice that the text in your supplied drawing is a lot smaller than my code produces.

 

I can changed the text element in my code to suit your specs if you wish?

 

No, no, have yourself some lunch and plan on making the most of my 5 sisters, mate. The table is sufficient for our purposes.

Link to comment
Share on other sites

All it needs to do additionally is add an L or R to say which side of the track it is on. Although if you can appreciate that some roads and rails are quite twisty(think of how rivers meander), it might be more of a challenge.

 

Maybe if you take a metre either side of the tangent point on the road or track, create a straight line, then align the ucs with that, you can use the coordinates of the block and point on the road or track to determine which side the point is on.

 

Maybe too complex for LISP?

Link to comment
Share on other sites

The concept shouldn't be too hard, as you already have the perpendicular point - the hard part is know which is right and which is left when the track meanders - You can't just set a rule like (if the x coordinate of the base point is greater/less than the x coord of the perp. point... etc etc then put right/left

 

I suppose you could look at the vector from perp point to base point and check out the direction, but then the left/right issue would still be there as you would have to look at previous points to know if it was right or left.

 

I.e. in the picture below, the direction of the track would also have to be known.

Example.jpg

Link to comment
Share on other sites

Well there is an up and down line for every tracl, so dont worry about which is which. Just go from left to right for this purpose.

 

The real concern would be a road that looks like a connection of joined up S's.

Link to comment
Share on other sites

All I can see working is taking a 1 metre piece of track for each block and creating a straight line to set the UCS about, then comparing coordinates relative to this.

 

If I select a fence round the objects on the left, run the lisp and then do the right side there is no problem.

 

Unless there is some way to make 2 regions in the drawing by closing the polylines.

 

I expect this will be easier in higher level languages, though.

Link to comment
Share on other sites

All I can see working is taking a 1 metre piece of track for each block and creating a straight line to set the UCS about, then comparing coordinates relative to this.

 

If I select a fence round the objects on the left, run the lisp and then do the right side there is no problem.

 

Unless there is some way to make 2 regions in the drawing by closing the polylines.

 

I expect this will be easier in higher level languages, though.

 

Nice idea, but as you say - easier in higher level languages.

 

For now I expect you shall have to select your blocks wisely.

Link to comment
Share on other sites

This is possibly a “non-issue” but interesting none the less.

 

The closest point from an object to a 3D polyline may not give meaningful information if:

 

But, the problem is, we need to ignore all the Z coords.

 

The attached example is exaggerated to illustrate the point.

3dPolyIssue.dwg

Link to comment
Share on other sites

> Lee Mac

 

About right and left side. Create a temporary curve using _OFFSET on minimal distance and measure the distance from the block to the main and to the temporary curve. Do you understand what I hinted?

Link to comment
Share on other sites

> SEANT, Lee Mac

 

This is possibly a “non-issue” but interesting none the less.

 

The closest point from an object to a 3D polyline may not give meaningful information if:

 

There is vlax-curve-getClosestPointToProjection function, especially for such cases.

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