Jump to content

Recommended Posts

Posted

hello everyone,

 

Im working on a lisp routine to create sheet metal layouts.

 

In my lisp routine I need to draw an ellipse.

its a 3d ellipse. I have 3 points: hp44 which is the center, highp which is the end of the major x axe and point p2701 which is the end of the minor x axe. The axis are of course tangent. Those 3 points are on a plane. The plane is most of the time parallel to the x-y plane on the ground. But some times there is a angle. In this case highp is always the highest point and the two others point are a little lower like 50 or 100 mm's.

 

I tried so far two thinks:

 

option 1:

 

(vl-load-com)

(setq acadObject (vlax-get-acad-object))

(setq acadDocument (vla-get-ActiveDocument acadObject))

(setq modelSpace (vla-get-ModelSpace (vla-get-ActiveDocument

(vlax-get-Acad-Object))))

 

(setq hp44 (list (car p44) (cadr p44) (- (caddr p44) (/ vers 2)))) ; defines hp44 (works good)

 

(setq longx (distance hp44 highp; sets major x axe not sure if I need the a length or just the point highp.

(setq shortx (distance hp44 p2701)); sets minor x axe which is always on the same hight as the centerpoint

 

(setq ellipse

(vla-addellipse modelSpace

(vlax-3d-point hp44)

(vlax-3d-point highp)

shortx))

 

After this the ellipse is not been drawn.

 

option 2

something like this:

(command "._ucs" "3" hp44 hoogp p2701) ;(works fine the ucs is extually on the right spot)

 

(command ".ellipse" "C" hp44 longx "r" shortx) ; I also tried this one:

(command ".ellipse" "C" hp44 highp "r" shortx)

 

option 2 doesnt work either.

 

I hope anyone can clear up some things.

Posted

Welcome to CADTutor Kingma.

 

Consider the following example function:

([color=BLUE]defun[/color] _3DEllipse ( cen minp majp )
   ([color=BLUE]entmake[/color]
       ([color=BLUE]list[/color]
          '(0 . [color=MAROON]"ELLIPSE"[/color])
          '(100 . [color=MAROON]"AcDbEntity"[/color])
          '(100 . [color=MAROON]"AcDbEllipse"[/color])
           ([color=BLUE]cons[/color] 010 cen)
           ([color=BLUE]cons[/color] 011 ([color=BLUE]mapcar[/color] '[color=BLUE]-[/color] majp cen))
           ([color=BLUE]cons[/color] 040 ([color=BLUE]/[/color] ([color=BLUE]distance[/color] minp cen) ([color=BLUE]distance[/color] majp cen)))
           ([color=BLUE]cons[/color] 210 (v^v ([color=BLUE]mapcar[/color] '[color=BLUE]-[/color] minp cen) ([color=BLUE]mapcar[/color] '[color=BLUE]-[/color] majp cen)))
       )
   )
)

[color=GREEN];; Vector Cross Product  -  Lee Mac[/color]
[color=GREEN];; Args: u,v - vectors in R^3[/color]

([color=BLUE]defun[/color] v^v ( u v )
   ([color=BLUE]list[/color]
       ([color=BLUE]-[/color] ([color=BLUE]*[/color] ([color=BLUE]cadr[/color] u) ([color=BLUE]caddr[/color] v)) ([color=BLUE]*[/color] ([color=BLUE]cadr[/color] v) ([color=BLUE]caddr[/color] u)))
       ([color=BLUE]-[/color] ([color=BLUE]*[/color] ([color=BLUE]car[/color]  v) ([color=BLUE]caddr[/color] u)) ([color=BLUE]*[/color] ([color=BLUE]car[/color]  u) ([color=BLUE]caddr[/color] v)))
       ([color=BLUE]-[/color] ([color=BLUE]*[/color] ([color=BLUE]car[/color]  u) ([color=BLUE]cadr[/color]  v)) ([color=BLUE]*[/color] ([color=BLUE]car[/color]  v) ([color=BLUE]cadr[/color]  u)))
   )
)

The above requires three point arguments expressed in WCS: the ellipse centre, the endpoint of the minor axis & the endpoint major axis.

 

Here is an example function to test:

([color=BLUE]defun[/color] c:test ( [color=BLUE]/[/color] cn p1 p2 )
   ([color=BLUE]if[/color] ([color=BLUE]and[/color]
           ([color=BLUE]setq[/color] cn ([color=BLUE]getpoint[/color] [color=MAROON]"\nCentre: "[/color]))
           ([color=BLUE]setq[/color] p1 ([color=BLUE]getpoint[/color] [color=MAROON]"\nEnd of Minor Axis: "[/color] cn))
           ([color=BLUE]setq[/color] p2 ([color=BLUE]getpoint[/color] [color=MAROON]"\nEnd of Major Axis: "[/color] cn))
       )
       (_3DEllipse ([color=BLUE]trans[/color] cn 1 0) ([color=BLUE]trans[/color] p1 1 0) ([color=BLUE]trans[/color] p2 1 0))
   )
   ([color=BLUE]princ[/color])
)

 

Assuming your points are defined in WCS, you could call the function in the following way:

(_3DEllipse hp44 p2701 highp)

 

Otherwise you will need to tranform your points to WCS using the trans function before calling the above ellipse function.

Posted (edited)

I don't know if dxf210 will accept non unit vector - my version is the same except dxf210...

(defun unit ( v )
 (mapcar '(lambda ( x ) (/ x (distance '(0.0 0.0 0.0) v))) v)
)

(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 ellipse3dpt ( cenpt endpt1 endpt2 / zd )
 (setq cenpt (trans cenpt 1 0) endpt1 (trans endpt1 1 0) endpt2 (trans endpt2 1 0))
 (setq zd (unit (v^v (mapcar '- endpt1 cenpt) (mapcar '- endpt2 cenpt))))
 (entmake 
   (list
     '(0 . "ELLIPSE")
     '(100 . "AcDbEntity")
     '(100 . "AcDbEllipse")
     (cons 10 cenpt)
     (cons 11 (mapcar '- endpt1 cenpt))
     (cons 210 zd)
     (cons 40 (/ (distance cenpt endpt2) (distance cenpt endpt1)))
     '(41 . 0.0)
     (cons 42 (* 2.0 pi))
   )
 )
 (princ)
)

M.R.

Edited by marko_ribar
added (trans pt 1 0)
Posted

Welcome to CADTutor Kingma. : Thank you Lee!

Thank you guys for replying so quickly!

Assuming your points are defined in WCS, you could call the function in the following way:

 

Code:

(_3DEllipse hp44 p2701 highp) This didnt work.

(Im using the wcs)

 

I did test your program c:TEST

I got the following error:

End of Major Axis; error; no function definition: _3dellipse

Posted
no function definition: _3dellipse

 

You didn't loaded first code... You have to load defined function _3dellipse in order to call it from another command function as c:test... If you want to draw ellipse from your code than you should copy+paste first code (defun _3dellipse ( ... / ... )) and (defun v^v ( u v ) ... ) above your code and when you want to make line for drawing ellipse than you write line with witch you call above defined functions that will be loaded with rest of your code where other variables are defined as center, endpt1, endpt2 (line for calling is : (_3dellipse center endpt1 endpt2)) where center is defined variable for center point of ellipse, endpt1 is your variable for endpoint on major axis, and endpt2 is your variable for endpoint on minor axis...

 

Or you can use my version; also copy+paste above your code and call it with :

(ellipse3dpt cen end1 end2)

where cen is your hp44; end1 is your p2701; end2 is your highp

or simply :

(ellipse3dpt hp44 p2701 highp)

M.R.

Posted
(_3DEllipse hp44 p2701 highp) This didnt work.

(Im using the wcs)

 

What error do you receive, if any?

 

I see no error in the code I have posted, and after testing, the programs perform successfully.

 

I did test your program c:TEST

I got the following error:

End of Major Axis; error; no function definition: _3dellipse

 

You will need to ensure the '_3DEllipse' function is loaded before calling it from my 'test' program.

 

PS: Please edit your posts and enclose your code with code tags:

 

[highlight][noparse]

[/noparse][/highlight] Your code here [highlight][noparse]

[/noparse][/highlight]

Posted

Oke is working :D Thank you for explaning. I didnt know you can put other programs in another.

Im one step futher finishing my program. :)

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