Jump to content

Autolisp giving error: bad argument type: "LINE" when trying to get line type


Erroreki

Recommended Posts

Hi!

 

Avid reader of the forums, first time poster.

 

I have a code with which I'm trying to extract the x and y coordinate of the startpoint of a line to the clipboard for pasting into another program. The problem is that when I run the lisp in Civil 3D it spits out

Quote

error: bad argument type: "LINE"

when running (caddr typelst) on line 6 in the code below. What could cause this. I'm having trouble understanding why it wouldn't be able to grab the type from the list.

 

The code:

(vl-load-com)
(defun c:copyx1y1 ()
	(setq choice (entsel "Choose the line whose start X and Y you want to copy \n"))
	(setq entname (car choice))
	(setq typelst (assoc 0 (entget entname)))
	(if (= (caddr typelst) "LINE")
		(progn
			(setq startpnt (assoc 10 (entget entname)))
			(setq x1 (cadr startpnt))
			(princ "\n")
			(princ x1)
			(princ "\n")
			(setq y1 (caddr startpnt))
			(princ y1)
			(setq copiedtxt (strcat (rtos x1) "\t" (rtos y1)))
			(setq result
				(vlax-invoke
					(vlax-get
						(vlax-get (setq htmlfile (vlax-create-object "htmlfile")) 'ParentWindow)
					'ClipBoardData)
				'SetData "Text" copiedtxt)
			)
			(vlax-release-object htmlfile)
			copiedtxt
		)
		(progn
			(princ "The choice is not of type LINE")
		)
	)
	(princ)
)

 

 

Regards,

 

E

Edited by Erroreki
Words missing in sentence
  • Like 1
Link to comment
Share on other sites

Got it fixed by replacing 

Quote

(caddr typelst)

with

Quote

(cdr typelst)

Didn't realise that dotted pair lists' values are called with cdr because it's a dotted PAIR and not a list with three elements per se.

 

E

Link to comment
Share on other sites

Welcome to the forums. Another way is to use ssget in point select mode. so it mimics entsel but only allows you to pick one entity and only what you put in the filter. this will do away with potentially selecting the wrong thing and having to check what you selected is the right thing.

 

(defun c:copyx1y1 (/ SS spt txt x1 yz html)
  (prompt "Choose the line whose start X and Y you want to copy \n")
  (if (setq SS (ssget "_+.:E:S" '((0 . "LINE"))))
    (progn
      (setq spt (assoc 10 (entget (ssname SS 0))))
      (prompt (strcat "\nX: " (setq x1 (rtos (cadr spt))) "\nY: " (setq y1 (rtos (caddr spt)))))
      (setq txt (strcat x1 " " y1))
      (vlax-invoke (vlax-get (vlax-get (setq html (vlax-create-object "htmlfile")) 'ParentWindow) 'ClipBoardData) 'setData "Text" txt)
      (vlax-release-object html)
    )
  )
  (princ)
)

 

Windows has a feature most people don't know/use. Instead of Ctrl + V you can use Windows key + V it will enable Clipboard history. and pop up a small window of all your past clips from that point on.

Edited by mhupp
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...