Jump to content

Need help with coordinates


cabltv1

Recommended Posts

Please help!

I need a a lisp routine to do the following...

1) Select one end of a Line or Pline (both are used), pause to select a block, then put the coordinates into the selected block attribute:Tag named "PT1".

2) Select other end of a Line or Pline (both are used), pause to select a block, then put the coordinates into the selected block attribute:Tag named "PT2".

 

Much thanks to anyone that can help.

Link to comment
Share on other sites

  • Replies 23
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    14

  • cabltv1

    9

  • techjunkie09

    1

Top Posters In This Topic

1 block with 2 seperate TAGS that need to be filled in "PT1" and "PT2". Picking the line once will be fine.

I need the coordinates in the TAGS to be in the following format...

2470263'-4.83",7002825'-4.30",0.00"

This is twice today you have helped me.

You helped earlier with picking a block to get the coordinates from then selecting another block to put the coordinates into. It works great except for one thing. I need it to have the below format...

2470263'-4.83",7002825'-4.30",0.00"

 

Thanks again Lee. Your help is greatly appreciated.

Link to comment
Share on other sites

This for now:

 

(defun c:lcoord (/ lEnt bEnt vEnt sPt ePt aEnt aEntLst)
 (vl-load-com)
 (if  (and (setq lEnt (car (entsel "\nSelect Curve >  ")))
       (member (cdr (assoc 0 (entget lEnt))) '("LINE" "POLYLINE" "LWPOLYLINE" "SPLINE" "ARC"))
       (setq bEnt (car (entsel "\nSelect Destination Block >  ")))
       (= (cdr (assoc 0 (entget bEnt))) "INSERT")
       (= (cdr (assoc 66 (entget bEnt))) 1))
   (progn
     (setq vEnt (vlax-ename->vla-object lEnt)
       sPt (vlax-curve-getStartPoint vEnt)
       ePt (vlax-curve-getEndPoint vEnt)
       aEnt (entnext bEnt))
     (while (/= "SEQEND" (cdr (assoc 0 (setq aEntLst (entget aEnt)))))
   (cond ((= "PT1" (cdr (assoc 2 aEntLst)))
          (setq aEntLst (subst (cons 1 (strcat (rtos (car sPt) 2 2) ","
                           (rtos (cadr sPt) 2 2) ","
                           (rtos (caddr sPt) 2 2)))
                   (assoc 1 aEntLst) aEntLst))
          (entmod aEntLst))
         ((= "PT2" (cdr (assoc 2 aEntLst)))
          (setq aEntLst (subst (cons 1 (strcat (rtos (car ePt) 2 2) ","
                           (rtos (cadr ePt) 2 2) ","
                           (rtos (caddr ePt) 2 2)))
                   (assoc 1 aEntLst) aEntLst))
          (entmod aEntLst)))
   (setq aEnt (entnext aEnt)))))
 (command "_regenall")
 (princ))
   

 

Will work on Arc, spline, line, pline, lwpline

Link to comment
Share on other sites

I need the coordinates in the TAGS to be in the following format...

2470263'-4.83",7002825'-4.30",0.00"

 

Do you want me to convert coords to feet/inches?

 

Or, if the coord is say:

 

3.5, 4.5, 6.5

 

then

 

3'-5",4'-5",6'-5"

 

?

Link to comment
Share on other sites

Man, your the best. It works like a charm.

As for the second part, I need the coordinates in Feet and Inches (see example below). The example below has a space on both sides of the comma but I can live without the spaces.

 

2470260'-2.45" , 7002781'-5.38"

 

Thanks again! I have been struggling with this for a couple of days.

Link to comment
Share on other sites

The space isn't too hard to accomodate - but as for the conversion, I think you may be able to change the units - although I am not sure if the units that I am retrieving have to be constant.

 

But in any case, engineering a code to convert to feet and inches shouldn't be too hard. I'll see what I can do. :thumbsup:

 

May have to be later though - I have a few lectures right now :P

Link to comment
Share on other sites

You can change the units that you view the coordinates in, by typing "units" into the command line and changing to architectural.

 

But the return when I retrieve the start and endpoints of the line are still the same (possibly in mm?).

Link to comment
Share on other sites

Lee,

I tried different "Unit" settings but it did not seem to change the attribute before or after I ran the routine. The code you gave me is in inches but is in this format

8.5

instead of this format

8'-6.00"

 

I am very greatfull for all of your help! You saved me a lot of trial and error. I can live with the current routine the way it currently works.

Thanks again.

Link to comment
Share on other sites

The code you gave me is in inches but is in this format

8.5

instead of this format

8'-6.00"

 

When you say it is in inches, do you mean the return is

 

8.5 inches?

 

i.e.

 

0'-8.50"

 

or 8.5 feet to be formatted as:

 

8'-6.00"

Link to comment
Share on other sites

If the result is indeed in inches, this should work:

 

(defun c:lcoord (/ lEnt bEnt vEnt sPt ePt aEnt aEntLst)
 (vl-load-com)
 (if  (and (setq lEnt (car (entsel "\nSelect Curve >  ")))
       (member (cdr (assoc 0 (entget lEnt))) '("LINE" "POLYLINE" "LWPOLYLINE" "SPLINE" "ARC"))
       (setq bEnt (car (entsel "\nSelect Destination Block >  ")))
       (= (cdr (assoc 0 (entget bEnt))) "INSERT")
       (= (cdr (assoc 66 (entget bEnt))) 1))
   (progn
     (setq vEnt (vlax-ename->vla-object lEnt)
       sPt (vlax-curve-getStartPoint vEnt)
       ePt (vlax-curve-getEndPoint vEnt)
       aEnt (entnext bEnt))
     (while (/= "SEQEND" (cdr (assoc 0 (setq aEntLst (entget aEnt)))))
   (cond ((= "PT1" (cdr (assoc 2 aEntLst)))
          (setq aEntLst (subst (cons 1 (strcat (in2ft (car sPt)) (chr 32) ","
                           (chr 32) (in2ft (cadr sPt)) (chr 32) ","
                           (chr 32) (in2ft (caddr sPt))))
                   (assoc 1 aEntLst) aEntLst))
          (entmod aEntLst))
         ((= "PT2" (cdr (assoc 2 aEntLst)))
          (setq aEntLst (subst (cons 1 (strcat (in2ft (car ePt)) (chr 32) ","
                           (chr 32) (in2ft (cadr ePt)) (chr 32) ","
                           (chr 32) (in2ft (caddr ePt))))
                   (assoc 1 aEntLst) aEntLst))
          (entmod aEntLst)))
   (setq aEnt (entnext aEnt)))))
 (command "_regenall")
 (princ))

(defun in2ft (num / ft in)
 (setq ft (fix (/ num 12.0))
   in (rem num 12.0))
 (strcat (rtos ft 2 2) (chr 39) (chr 45)
     (rtos in 2 2) (chr 34)))

Link to comment
Share on other sites

  • 5 months later...

Lee,

 

Your last post for this thread works great except. I was wondering what portion of the code I could modify to eliminate some of the zeros?

modify_coord.jpg

Link to comment
Share on other sites

Lee,

 

That is the code I used in the example. It works perfectly but I didn't notice the trailing zeros at the time.

I just tried that code again to make sure and they are still there.

fix_coord3.jpg

In the example the figure for PT1 is 983.00'-0.74", -2885.00'-3.90", 0.00'-0.00".

I am trying to remove the (.00) in red.

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