Jump to content

Direction of a construction line (xline)


TunzaGibbo

Recommended Posts

 

I'm trying to write a small lisp file to do the following:

I have a line which has comes from the command _xline. I don't believe this type of line has end points because I think it goes to infinity.

I want to be able to touch on this xline and be able to get the angle of this xline.

The reason for this is so that when I touch the line I will automatically get an xline rotated 90 degrees and ready to place somewhere in the drawing.

 

Any help would be appreciated

 

Regards

tony 

 

 

Link to comment
Share on other sites

  • Replies 24
  • Created
  • Last Reply

Top Posters In This Topic

  • TunzaGibbo

    13

  • Tharwat

    10

  • BIGAL

    1

  • Grrr

    1

Top Posters In This Topic

Posted Images

5 minutes ago, TunzaGibbo said:

Tharwat

Thanks for that. Can you explain how this works

And what command would you use to select the xline

Like this.

(if (and (princ "\nSelect Xline :")
         (setq sel (ssget "_+.:E:S" '((0 . "XLINE"))))
    )
  (angle '(0. 0. 0.) (cdr (assoc 11 (entget (ssname sel 0)))))
)

Be informed is that the angle value would be in Radians.

Link to comment
Share on other sites

Thanks again.

you are obviously good at Lisp unlike me who is learning. Which leaves me at a bit of a loss about your code.

I understand up to "ssget" and are not sure what the rest of the line is saying.

On the next line I understand "angle" but have never used it in this way. Is there a variable created for the angle of the line

 

Link to comment
Share on other sites

2 hours ago, TunzaGibbo said:

Thanks again.

you are obviously good at Lisp unlike me who is learning. Which leaves me at a bit of a loss about your code.

I understand up to "ssget" and are not sure what the rest of the line is saying.

On the next line I understand "angle" but have never used it in this way. Is there a variable created for the angle of the line

 

You're welcome.

 

You can a variable to the return value of angle as follows:

(setq ang (angle '(0. 0. 0.) (cdr (assoc 11 (entget (ssname sel 0))))))

 

Edited by Tharwat
Link to comment
Share on other sites

Hi Tharwat

 

I've gotten this far but can't get the entry for the angle (where the ??? are)

(defun c:qqq () ;(/ sel ang)
  (savevartoold) (constructionlayer)  
    (if (and (princ "\nSelect Xline :")
    (setq sel (ssget "_+.:E:S" '((0 . "XLINE")))))
    (setq ang (angle '(0. 0. 0.) (cdr (assoc 11 (entget (ssname sel 0)))))))
    (command "_xline" "A" ?????? pause "")
  (restoldvar)
 (princ)
)

Thanks for your help

 

tony

Link to comment
Share on other sites

Give this a shot and be sure is that your added sub-functions are working as well.

(defun c:qqq (/ sel ang)
  (savevartoold)
  (constructionlayer)
  (if (and (princ "\nSelect Xline :")
           (setq sel (ssget "_+.:E:S" '((0 . "XLINE"))))
           (setq ang (angle '(0. 0. 0.)
                            (cdr (assoc 11
                                        (entget (ssname
                                                  sel
                                                  0
                                                )
                                        )
                                 )
                            )
                     )
           )
      )
    (command "_xline" "A" (/ (* ang 180.0) pi))
  )
  (restoldvar)
  (princ)
)

 

Link to comment
Share on other sites

I got rid of the 3 sub functions and the program ran. Why won't it work with them??

 

Unfortunately the program doesn't correctly.

As an example I have a construction line (XLINE) in my drawing which is at lets say 45 deg. The idea behind this lisp is to select the 45 deg line and have the program produce another construction line (XLINE) at 90 degrees to the selected line. So I would end up with a 90 degree cross.

Sorry to be a pain

 

Regards

 

Tony

Link to comment
Share on other sites

That means is that your functions or one of them is reducing that error message which caused the program to exit with error so you need to correct them in prior.

 

If you would like to add 90 Deg. to the angle of the selected Xline then just add it like this:

(setq ang (+ (* pi 0.5) (angle '(0. 0. 0.) (cdr (assoc 11 (entget (ssname sel 0)))))))

 

Link to comment
Share on other sites

I'm just not getting this. This is "Getting too many arguments"

(defun c:qqq (/ sel ang)
  ;(savevartoold)
  ;(constructionlayer)
  (if (and (princ "\nSelect Xline :")
    (setq sel (ssget "_+.:E:S" '((0 . "XLINE"))))
    (setq ang (+ (* pi 0.5) (angle '(0. 0. 0.) (cdr
    (assoc 11 (entget (ssname sel 0)))))))))

    (command "_xline" "A" (/ (* ang 180.0) pi))
 ; (restoldvar)
  (princ)
)

 

Link to comment
Share on other sites

yes I have got now

I have included the command line in the if statement and it works.

 

Just have to get the subroutines fixed now

 

what would change if I wanted the to select a line or a xline

Link to comment
Share on other sites

(defun c:qqq (/ sel ang lst)
  (if (and (princ "\nSelect Xline or LINE :")
           (setq sel (ssget "_+.:E:S" '((0 . "XLINE,LINE"))))
           (setq ang
                  (+ (* pi 0.5)
                     (angle (if (= (cdr (assoc 0 (setq lst (entget (ssname sel 0))))) "XLINE")
                              '(0. 0. 0.)
                              (cdr (assoc 10 lst))
                       )
                       (cdr (assoc 11 lst))
                     )
                  )
           )
      )
    (command "_xline" "A" (/ (* ang 180.0) pi))
  )
  (princ)
)

 

Link to comment
Share on other sites

All works good

Thank you very much for your help

I really appreciate that. I wish I could help you but I don't think you need it.

 

All the best

 

Tony

Link to comment
Share on other sites

Hi Tharwat

Is there a line of code that I can use to get the the following info by just touching an entity.

The entity is a line and I need:

The length 

The start & end point

The angle

 

Regards

Tony

Link to comment
Share on other sites

Hi,

(setq ent (car (entsel "\nSelect line :")))
(setq lst (entget ent))
(setq startpoint (cdr (assoc 10 lst)))
(setq end (cdr (assoc 11 lst)))
(setq len (distance startpoint end)) ;; length
(setq ang (angle startpoint end))

 

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