Jump to content

3DArc: Lisp Error : error: bad argument type: 2D/3D point


Recommended Posts

Posted

I made a LISP to generate 3D arc from the CSV file.

(defun c:rects ()
(setq f (open "D:/3DY/FromAutoCAD/Circle.csv" "r")) 
(setq dataline (read-line f))             
(setq dataline (read-line f))
(setq x 1)
(setq a 0)
(setq b 0)
(setq c 0)           
(while (/= dataline "EOF")
(vl-string-left-trim " " dataline)
(vl-string-right-trim " " dataline)
(if ( = (rem x 3) 0)
    (progn 
        (setq c dataline)
        (princ a)
        (princ b)
        (princ c)
        (command "_ucs" "_w")
        (command "_ucs" "_3p" a b c)
        (command "_arc" (trans a 0 1)(trans b 0 1)(trans c 0 1))
        (command "_ucs" "_w")
    )
)
(if ( = (rem x 3) 1)
    (setq a dataline)
)
(if ( = (rem x 3) 2)
    (setq b dataline)
)
(setq x (+ 1 x))
(setq dataline (read-line f))  
)                                            
(close f)                                  
)

Sample of CSV file

X,Y,Z
221931.63200000036,401253.0739999904,18.268999970437235
221934.92300012588,401257.3900002136,18.269000183106428
221939.25799999948,401259.3889999542,18.23599997806663
221919.44000004293,401265.3299999994,18.11499998617286
221924.67399997663,401259.0890000062,18.223000026227183
221924.88300002765,401255.6249999981,18.25399998474235

But while running it, I am facing an error.

Command: RECTS
221931.63200000036,401253.0739999904,18.268999970437235221934.92300012588,401257.3900002136,18.269000183106428221939.25799999948,401259.3889999542,18.23599997806663_ucs
Current ucs name:  *WORLD*
Specify origin of UCS or [Face/NAmed/OBject/Previous/View/World/X/Y/Z/ZAxis] <World>: _w
Command: _ucs
Current ucs name:  *WORLD*
Specify origin of UCS or [Face/NAmed/OBject/Previous/View/World/X/Y/Z/ZAxis] <World>: _3p
Specify new origin point <0,0,0>: 221931.63200000036,401253.0739999904,18.268999970437235
Specify point on positive portion of X-axis <221932.6320,401253.0740,18.2690>: 221934.92300012588,401257.3900002136,18.269000183106428
Specify point on positive-Y portion of the UCS XY plane <221930.8368,401253.6803,18.2690>: 221939.25799999948,401259.3889999542,18.23599997806663
Command: _arc
Specify start point of arc or [Center]: ; error: bad argument type: 2D/3D point: "221931.63200000036,401253.0739999904,18.268999970437235"

I have check my ARC generation code part with another lisp code, which is working as expected, no error.

(defun c:3Darc (/ p1 p2 p3)
 (command "_ucs" "_w")
 (setq p1 (getpoint "Arc point #1: "))
 (setq p2 (getpoint "Arc point #2: "))
 (setq p3 (getpoint "Arc point #3: "))
 (command "_ucs" "_3p" p1 p2 p3)
 (command "_arc" (trans p1 0 1)(trans p2 0 1)(trans p3 0 1))
 (command "_ucs" "_w")
)

 

Please help to solve this.

 

Thanks,

Yash

Posted (edited)

Hello i modify your code and thik this may work for you.

If i understand correct every 3 point from your list is different arc.

 

(defun T:spaceremover (lst / ttr ttr2)
	(setq ttr (subst 32 44 (subst 32 9 (vl-string->list lst))))
		(repeat (length ttr)
			(if (and (= (car ttr) 32) (= (cadr ttr) 32)) (princ) (setq ttr2 (cons (car ttr) ttr2)))
			(setq ttr (cdr ttr))
		)
	(vl-string-trim " " (vl-list->string (reverse ttr2)))
)

(defun LM:group<n ( l n / a b m )
    (while l
        (setq m n)
        (while (and l (< 0 m))
            (setq a (cons (car l) a)
                  l (cdr l)
                  m (1- m)
            )
        )
        (setq b (cons (reverse a) b)
              a nil
        )
    )
    (reverse b)
)

(defun c:try1 (/ f dataline lst str lst2 lst3 lst4)
(setq f (open "C:\\Trudy-menu\\Lisp\\all_Lisp\\3d_arc\\try1.csv" "r"))
   
  (while 
	(setq dataline (read-line f))   
    (setq lst (cons dataline lst))
  )
  
  (setq lst (reverse lst))
(repeat (- (length lst) 1) 
	(setq str (T:spaceremover (car (cdr lst))))
 		(setq lst2 nil)
        (setq i 0 n (strlen " "))
			(while (setq j (vl-string-search " " str i))
				   (setq lst2 (cons (atof (substr str (1+ i)(- j i))) lst2)
								i (+ j n)
					)
			)
		(setq lst2 (reverse (cons (atof (substr str (1+ i))) lst2))) 
		(setq lst3 (cons lst2 lst3))
		(setq lst (cdr lst))
)


(setq lst4 (LM:group<n (reverse lst3) 3))
(repeat (length lst4)
	(if (= (length (car lst4)) 3)
			(progn 
			
				(command "_ucs" "_w")
				(command "_ucs" "_3p" (nth 0 (car lst4)) (nth 1 (car lst4)) (nth 2 (car lst4)))
				(command "arc" (trans (nth 0 (car lst4)) 0 1) (trans (nth 1 (car lst4)) 0 1) (trans (nth 2 (car lst4)) 0 1))
				(command "_ucs" "_w")
			)
	)
	(setq lst4 (cdr lst4))
)
(close f) 
(princ)
)

  

 

Edited by Trudy
  • Thanks 1
Posted
8 hours ago, Yash Chauhan said:

I made a LISP to generate 3D arc from the CSV file.


(defun c:rects ()
(setq f (open "D:/3DY/FromAutoCAD/Circle.csv" "r")) 
(setq dataline (read-line f))             
(setq dataline (read-line f))
(setq x 1)
(setq a 0)
(setq b 0)
(setq c 0)           
(while (/= dataline "EOF")
(vl-string-left-trim " " dataline)
(vl-string-right-trim " " dataline)
(if ( = (rem x 3) 0)
    (progn 
        (setq c dataline)
        (princ a)
        (princ b)
        (princ c)
        (command "_ucs" "_w")
        (command "_ucs" "_3p" a b c)
        (command "_arc" (trans a 0 1)(trans b 0 1)(trans c 0 1))
        (command "_ucs" "_w")
    )
)
(if ( = (rem x 3) 1)
    (setq a dataline)
)
(if ( = (rem x 3) 2)
    (setq b dataline)
)
(setq x (+ 1 x))
(setq dataline (read-line f))  
)                                            
(close f)                                  
)

Sample of CSV file

X,Y,Z
221931.63200000036,401253.0739999904,18.268999970437235
221934.92300012588,401257.3900002136,18.269000183106428
221939.25799999948,401259.3889999542,18.23599997806663
221919.44000004293,401265.3299999994,18.11499998617286
221924.67399997663,401259.0890000062,18.223000026227183
221924.88300002765,401255.6249999981,18.25399998474235

But while running it, I am facing an error.


Command: RECTS
221931.63200000036,401253.0739999904,18.268999970437235221934.92300012588,401257.3900002136,18.269000183106428221939.25799999948,401259.3889999542,18.23599997806663_ucs
Current ucs name:  *WORLD*
Specify origin of UCS or [Face/NAmed/OBject/Previous/View/World/X/Y/Z/ZAxis] <World>: _w
Command: _ucs
Current ucs name:  *WORLD*
Specify origin of UCS or [Face/NAmed/OBject/Previous/View/World/X/Y/Z/ZAxis] <World>: _3p
Specify new origin point <0,0,0>: 221931.63200000036,401253.0739999904,18.268999970437235
Specify point on positive portion of X-axis <221932.6320,401253.0740,18.2690>: 221934.92300012588,401257.3900002136,18.269000183106428
Specify point on positive-Y portion of the UCS XY plane <221930.8368,401253.6803,18.2690>: 221939.25799999948,401259.3889999542,18.23599997806663
Command: _arc
Specify start point of arc or [Center]: ; error: bad argument type: 2D/3D point: "221931.63200000036,401253.0739999904,18.268999970437235"

I have check my ARC generation code part with another lisp code, which is working as expected, no error.


(defun c:3Darc (/ p1 p2 p3)
 (command "_ucs" "_w")
 (setq p1 (getpoint "Arc point #1: "))
 (setq p2 (getpoint "Arc point #2: "))
 (setq p3 (getpoint "Arc point #3: "))
 (command "_ucs" "_3p" p1 p2 p3)
 (command "_arc" (trans p1 0 1)(trans p2 0 1)(trans p3 0 1))
 (command "_ucs" "_w")
)

 

Please help to solve this.

 

Thanks,

Yash

 

 

This is not something I do at all. An arc is a 2D entity but can be drawn as a 2d object in a different ucs. Logic (and I could be wrong here) says if you are setting up a ucs from three points, then they are already in that usc and so you don't need to (trans) them. Have you tried just drawing the arc  as

 

(command "_arc" p1 p2 p3) ?

 

 

 

Posted

@dlanorh

I think you are wrong - OP IMHO did just what should with (trans) although - there is missing token "_non" from command call when supplying points to ARC command...

Posted

Logic says, 3 points always form a plane. Then from that you can identify the center and everything. I'll type up something shortly

Posted

Maybe note the 3pt order for the ucs I think thats were not working

 

(command "_ucs" "_w")
(setq p1 (LIST 221931.63200000036 401253.0739999904 18.268999970437235))
(setq p2 (LIST 221934.92300012588 401257.3900002136 18.269000183106428))
(setq p3 (LIST 221939.25799999948 401259.3889999542 18.23599997806663))
(SETVAR 'OSMODE 0)
(command "ucs" "_3P" p1 P3 P2 )
(command "_arc" (trans p1 0 1)(trans p2 0 1)(trans p3 0 1))
(command "_ucs" "_w")

 

Posted
18 hours ago, Trudy said:

Hello i modify your code and thik this may work for you.

If i understand correct every 3 point from your list is different arc.

 


(defun T:spaceremover (lst / ttr ttr2)
	(setq ttr (subst 32 44 (subst 32 9 (vl-string->list lst))))
		(repeat (length ttr)
			(if (and (= (car ttr) 32) (= (cadr ttr) 32)) (princ) (setq ttr2 (cons (car ttr) ttr2)))
			(setq ttr (cdr ttr))
		)
	(vl-string-trim " " (vl-list->string (reverse ttr2)))
)

(defun LM:group<n ( l n / a b m )
    (while l
        (setq m n)
        (while (and l (< 0 m))
            (setq a (cons (car l) a)
                  l (cdr l)
                  m (1- m)
            )
        )
        (setq b (cons (reverse a) b)
              a nil
        )
    )
    (reverse b)
)

(defun c:try1 (/ f dataline lst str lst2 lst3 lst4)
(setq f (open "C:\\Trudy-menu\\Lisp\\all_Lisp\\3d_arc\\try1.csv" "r"))
   
  (while 
	(setq dataline (read-line f))   
    (setq lst (cons dataline lst))
  )
  
  (setq lst (reverse lst))
(repeat (- (length lst) 1) 
	(setq str (T:spaceremover (car (cdr lst))))
 		(setq lst2 nil)
        (setq i 0 n (strlen " "))
			(while (setq j (vl-string-search " " str i))
				   (setq lst2 (cons (atof (substr str (1+ i)(- j i))) lst2)
								i (+ j n)
					)
			)
		(setq lst2 (reverse (cons (atof (substr str (1+ i))) lst2))) 
		(setq lst3 (cons lst2 lst3))
		(setq lst (cdr lst))
)


(setq lst4 (LM:group<n (reverse lst3) 3))
(repeat (length lst4)
	(if (= (length (car lst4)) 3)
			(progn 
			
				(command "_ucs" "_w")
				(command "_ucs" "_3p" (nth 0 (car lst4)) (nth 1 (car lst4)) (nth 2 (car lst4)))
				(command "arc" (trans (nth 0 (car lst4)) 0 1) (trans (nth 1 (car lst4)) 0 1) (trans (nth 2 (car lst4)) 0 1))
				(command "_ucs" "_w")
			)
	)
	(setq lst4 (cdr lst4))
)
(close f) 
(princ)
)

  

 

Many thanks for the help :) 

Posted (edited)

Hi Yash,

 

This is a way to do it without using the (command) feature using your original code:

 

(defun c:rects ( / a b c dataline f x)
    (setq f (open "D:/3DY/FromAutoCAD/Circle.csv" "r"))
    (setq dataline (read-line f))
    (setq dataline (read-line f))
    (setq x 1)
    (setq a 0)
    (setq b 0)
    (setq c 0)
    (while (/= dataline "EOF")
	(setq dataline (vl-string-trim " " dataline))
	(cond
	    ((= (rem x 3) 0)
	     (setq c (mapcar 'atof (JH:str->lst dataline ",")))
	     (3Darc a b c)
	     )
	    ((= (rem x 3) 1)
	     (setq a (mapcar 'atof (JH:str->lst dataline ",")))
	     )
	    ((= (rem x 3) 2)
	     (setq b (mapcar 'atof (JH:str->lst dataline ",")))
	     )
	    )
	(setq x (+ 1 x))
	(setq dataline (read-line f))
	)
    (close f)
    )

(defun 3DArc (p1 p2 p3 / cen n1 m1 m2 z1 z2 z3)
    (setq n1 (vx1 (v^v (mapcar '- p1 p2) (mapcar '- p3 p2))))
    (mapcar
	'(lambda (x z)
	     (set z
		  (mapcar
		      '(lambda (y)
			   (if (< (abs y) 1e-8) 0.0 y)
			   )
		      (trans x 0 n1)
		      )
		  )
	     )
	(list p1 p2 p3)
	'(z1 z2 z3)
	)
    (setq m1 (mapcar '(lambda (x y) (/ (+ x y) 2.0)) z1 z2)
	  m2 (mapcar '(lambda (x y) (/ (+ x y) 2.0)) z2 z3)
	  cen
	     (inters
		 m1 (polar m1 (+ (* 0.5 pi) (angle z1 z2)) 1)
		 m2 (polar m2 (+ (* 0.5 pi) (angle z2 z3)) 1)
		 nil
		 )
	  )
    (entmake
	(list
	    '(0 . "ARC")
	    (cons 10 cen)
	    (cons 40 (distance cen z1))
	    (cons 50 (angle cen z3))
	    (cons 51 (angle cen z1))
	    (cons 210 n1)
	    )
	)
    
    )

(defun v^v ( u v )
    (list
        (- (* (cadr u) (caddr v)) (* (cadr v) (caddr u)))
        (- (* (car  v) (caddr u)) (* (car  u) (caddr v)))
        (- (* (car  u) (cadr  v)) (* (car  v) (cadr  u)))
    )
)

(defun vx1 ( v )
    (   (lambda ( n ) (if (equal 0.0 n 1e-10) nil (mapcar '/ v (list n n n))))
        (distance '(0.0 0.0 0.0) v)
    )
)

;; JH:str->lst --> Jonathan Handojo
;; Parses a string into a list using a specified delimiter
;; str - string to parse
;; del - delimiter string

(defun JH:str->lst (str del / l rtn src)
    (setq l (1+ (strlen del)))
    (while (setq src (vl-string-search del str))
	(setq rtn (cons (substr str 1 src) rtn)
	      str (substr str (+ src l))
	      )
	)
    (reverse (cons str rtn))
    )

 

Heck why am I even doing so much work for something that can be solved using the (command) feature, lol

Edited by Jonathan Handojo
  • Thanks 1

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