AddLightweightPolyline and UCS
CADForums.net Forum Index CADForums.net
Discussion of AutoCAD and other CAD software.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web cadforums.net
AddLightweightPolyline and UCS
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CADForums.net Forum Index -> Customization
Author Message
Jason Piercey
Guest





Posted: Thu Jan 06, 2005 6:41 am    Post subject: AddLightweightPolyline and UCS Reply with quote

In the process of fine tuning a routine that generates
the boundary which defines a named view, I thought it
would be nice to include any required transformations
of coordinate systems.

What I have written thus far code wise works fine if I
use the command function to draw the boundary but
when trying to use AddLightweightPolyline things don't
quite work the same.

The help file says that AddLightweightPolyline needs
"The array of 2D OCS coordinates ...."

(vlax-invoke <modelspace> 'AddLightweightPolyline <lst>)

So, do I need to translate <lst> from UCS to OCS? Didn't
see an OCS option in docs on the trans function, other than
using an ename (which doesn't appear to work when passing
a named view's ename)

What am I missing/overlooking?

Back to top
Kelie Feng
Guest





Posted: Thu Jan 06, 2005 9:15 am    Post subject: Re: AddLightweightPolyline and UCS Reply with quote

Jason,

I used vla-AddLightweightPolyline in a routine to draw paperspace viewport
boundary in modelspace and I just used the coordinates in WCS. Worked fine.

--
Regards,
Kelie


"Jason Piercey" <nomail> wrote in message news:41dc971f$1_2@newsprd01...
Quote:
In the process of fine tuning a routine that generates
the boundary which defines a named view, I thought it
would be nice to include any required transformations
of coordinate systems.

What I have written thus far code wise works fine if I
use the command function to draw the boundary but
when trying to use AddLightweightPolyline things don't
quite work the same.

The help file says that AddLightweightPolyline needs
"The array of 2D OCS coordinates ...."

(vlax-invoke <modelspace> 'AddLightweightPolyline <lst>)

So, do I need to translate <lst> from UCS to OCS? Didn't
see an OCS option in docs on the trans function, other than
using an ename (which doesn't appear to work when passing
a named view's ename)

What am I missing/overlooking?

Back to top
BillZ
Guest





Posted: Thu Jan 06, 2005 5:03 pm    Post subject: Re: AddLightweightPolyline and UCS Reply with quote

I use the add3dpoly method for 3d stuff.

It only needs the wcs coords.

(setq Rec_1 (vlax-invoke *mspace* 'Add3dPoly (apply 'append (list r1p1 r1p2 r1p3)))


Bill

Back to top
Jason Piercey
Guest





Posted: Thu Jan 06, 2005 7:12 pm    Post subject: Re: AddLightweightPolyline and UCS Reply with quote

Hi Kelie,

That works fine if the UCS and WCS are the same.
I figured that if they were not the same my routine
should still place the boundary in the correct spot.

--
Autodesk Discussion Group Facilitator



"Kelie Feng" <nospam@address.withheld> wrote in message
news:41dcbad6$1_2@newsprd01...
Quote:
Jason,

I used vla-AddLightweightPolyline in a routine to draw paperspace viewport
boundary in modelspace and I just used the coordinates in WCS. Worked
fine.

--
Regards,
Kelie


"Jason Piercey" <nomail> wrote in message news:41dc971f$1_2@newsprd01...
In the process of fine tuning a routine that generates
the boundary which defines a named view, I thought it
would be nice to include any required transformations
of coordinate systems.

What I have written thus far code wise works fine if I
use the command function to draw the boundary but
when trying to use AddLightweightPolyline things don't
quite work the same.

The help file says that AddLightweightPolyline needs
"The array of 2D OCS coordinates ...."

(vlax-invoke <modelspace> 'AddLightweightPolyline <lst>)

So, do I need to translate <lst> from UCS to OCS? Didn't
see an OCS option in docs on the trans function, other than
using an ename (which doesn't appear to work when passing
a named view's ename)

What am I missing/overlooking?



Back to top
Jason Piercey
Guest





Posted: Thu Jan 06, 2005 7:19 pm    Post subject: Re: AddLightweightPolyline and UCS Reply with quote

Hi Bill,

I don't really need a 3dpoly, a simple lightweight
should work fine. Take a 2d named view, change
the ucs so it is a different plane than the view, and
draw a boundary around it.

My immediate need was just for 2d "plan" views
but I could also use this for 3d views (on occasion)
so I thought I'd try to get a handle on any required
TRANSing (using the 2d views with an "odd" ucs).

After I get this part squared away, I'll incorporate
any clipping planes that are present.

--
Autodesk Discussion Group Facilitator



"BillZ" <nospam@address.withheld> wrote in message
news:30376375.1105013067802.JavaMail.jive@jiveforum1.autodesk.com...
Quote:
I use the add3dpoly method for 3d stuff.

It only needs the wcs coords.

(setq Rec_1 (vlax-invoke *mspace* 'Add3dPoly (apply 'append (list r1p1
r1p2 r1p3)))


Bill
Back to top
Kelie Feng
Guest





Posted: Thu Jan 06, 2005 9:57 pm    Post subject: Re: AddLightweightPolyline and UCS Reply with quote

Jason,

Seems to me the lwpolyline will always be placed in the right coordinates if
WCS coordinates are supplied. I had wondered about what's said in the
documentation regarding OCS as well.

--
Regards,
Kelie


"Jason Piercey" <Jason AT atreng DOT com> wrote in message
news:41dd4744$1_1@newsprd01...
Quote:
Hi Kelie,

That works fine if the UCS and WCS are the same.
I figured that if they were not the same my routine
should still place the boundary in the correct spot.

--
Autodesk Discussion Group Facilitator



"Kelie Feng" <nospam@address.withheld> wrote in message
news:41dcbad6$1_2@newsprd01...
Jason,

I used vla-AddLightweightPolyline in a routine to draw paperspace
viewport
boundary in modelspace and I just used the coordinates in WCS. Worked
fine.

--
Regards,
Kelie


"Jason Piercey" <nomail> wrote in message news:41dc971f$1_2@newsprd01...
In the process of fine tuning a routine that generates
the boundary which defines a named view, I thought it
would be nice to include any required transformations
of coordinate systems.

What I have written thus far code wise works fine if I
use the command function to draw the boundary but
when trying to use AddLightweightPolyline things don't
quite work the same.

The help file says that AddLightweightPolyline needs
"The array of 2D OCS coordinates ...."

(vlax-invoke <modelspace> 'AddLightweightPolyline <lst>)

So, do I need to translate <lst> from UCS to OCS? Didn't
see an OCS option in docs on the trans function, other than
using an ename (which doesn't appear to work when passing
a named view's ename)

What am I missing/overlooking?





Back to top
T.Willey
Guest





Posted: Thu Jan 06, 2005 10:13 pm    Post subject: Re: AddLightweightPolyline and UCS Reply with quote

I'm not sure if this is the same thing, but I have a routine that draws a polyline around the area that is defined by a viewport. Once I get those points I switch to model space and trans those points like
(setq PtList (mapcar '(lambda (x) (trans x 0 2)) PtList))
and it seems to work when the viewport ucs is different then the model space ucs.

Hope that helps, if not forget I posted here.
Tim
Back to top
BillZ
Guest





Posted: Thu Jan 06, 2005 11:49 pm    Post subject: Re: AddLightweightPolyline and UCS Reply with quote

Jason,
I use this one from Jeff M.
Doesn't seem to need any trans and seems to work in any ucs.

Code:
;Reply From: Jeff Mishler
;Date: Mar/24/04 - 21:39 (CST)
;Draw a rectangle from list of points.
;
;
(defun drawsquare (leg pt / coord1 pline)
(vl-load-com)
(setq pt (reverse (cdr (reverse pt))))
(setq coord1 (polar pt (angtof "225" 0) (* (sqrt 2) leg)))
(setq coord1 (append (polar pt (angtof "135" 0) (* (sqrt 2) leg)) coord1))
(setq coord1 (append (polar pt (angtof "45" 0) (* (sqrt 2) leg)) coord1))
(setq coord1 (append (polar pt (angtof "315" 0) (* (sqrt 2) leg)) coord1))
(setq pline (vlax-invoke
(vla-get-modelspace
(vla-get-activedocument
(vlax-get-acad-object)))
"addlightweightpolyline"
coord1
)
)
(vla-put-closed pline :vlax-true)
)

(defun c:sqr (/ leg pt)
(if (and
(setq leg (getdist "\nLength of side of square: "))
(setq pt (getpoint "\nSelect centerpoint of square: "))
)
(drawsquare leg pt)
)
(princ)
)


Bill
Back to top
Jason Piercey
Guest





Posted: Fri Jan 07, 2005 12:04 am    Post subject: Re: AddLightweightPolyline and UCS Reply with quote

I was using this.

; function to create a list of points representing
; the outline of a box based on the center point,
; width and height of the box.
; Arguments:
; [center] - list, 2d point
; [width] - integer or real, width of outline
; [height] - integer or real, height of outline
; returns: list of points
(defun getCornersFromCenter (center width height)
(setq height (/ height 2.0))
(setq width (/ width 2.0))
(list
(mapcar '+ center (list (- width) (- height)))
(mapcar '+ center (list width (- height)))
(mapcar '+ center (list width height))
(mapcar '+ center (list (- width) height))
)
)


I'll try and post some other code today, right now
I've got too much real work getting in the way.


--
Autodesk Discussion Group Facilitator



"BillZ" <nospam@address.withheld> wrote in message
news:25887295.1105037402958.JavaMail.jive@jiveforum1.autodesk.com...
Quote:
Jason,
I use this one from Jeff M.
Doesn't seem to need any trans and seems to work in any ucs.

Code:
;Reply From: Jeff Mishler
;Date: Mar/24/04 - 21:39 (CST)
;Draw a rectangle from list of points.
;
;
(defun drawsquare (leg pt / coord1 pline)
(vl-load-com)
(setq pt (reverse (cdr (reverse pt))))
(setq coord1 (polar pt (angtof "225" 0) (* (sqrt 2) leg)))
(setq coord1 (append (polar pt (angtof "135" 0) (* (sqrt 2) leg)) coord1))
(setq coord1 (append (polar pt (angtof "45" 0) (* (sqrt 2) leg)) coord1))
(setq coord1 (append (polar pt (angtof "315" 0) (* (sqrt 2) leg)) coord1))
(setq pline (vlax-invoke
(vla-get-modelspace
(vla-get-activedocument
(vlax-get-acad-object)))
"addlightweightpolyline"
coord1
)
)
(vla-put-closed pline :vlax-true)
)

(defun c:sqr (/ leg pt)
(if (and
(setq leg (getdist "\nLength of side of square: "))
(setq pt (getpoint "\nSelect centerpoint of square: "))
)
(drawsquare leg pt)
)
(princ)
)


Bill
Back to top
BillZ
Guest





Posted: Fri Jan 07, 2005 12:14 am    Post subject: Re: AddLightweightPolyline and UCS Reply with quote

Quote:
I've got too much real work getting in the way.

I'm in the same boat. :)

Although Jeffs puts the rectangle on the right plane, I now see that it was rotated in z axis.

I'll look at it later.

Bill
Back to top
James Allen
Guest





Posted: Fri Jan 07, 2005 1:22 am    Post subject: Re: AddLightweightPolyline and UCS Reply with quote

BillZ wrote > Doesn't seem to need any trans and seems to work in any ucs.

Only if the current ucs happens to be coincide with the "current" ocs.
Adding a trans using the ocs normal vector takes care of it as follows.
--
James Allen, EIT
Malicoat-Winslow Engineers, P.C.
Columbia, MO


;Reply From: Jeff Mishler
;Date: Mar/24/04 - 21:39 (CST)
;Draw a rectangle from list of points.
;
;
;Modified 06Jan05 by James Allen for arbitrary ucs
(defun drawsquare (leg pt / coord1 ocs pline)
(vl-load-com)
(setq coord1 (cons (polar pt (angtof "225" 0) (* (sqrt 2) leg)) coord1)
coord1 (cons (polar pt (angtof "135" 0) (* (sqrt 2) leg)) coord1)
coord1 (cons (polar pt (angtof "45" 0) (* (sqrt 2) leg)) coord1)
coord1 (cons (polar pt (angtof "315" 0) (* (sqrt 2) leg)) coord1)
ocs (MWE:CrossProd (list (getvar "ucsxdir") (getvar "ucsydir")))
coord1 (mapcar
'(lambda (a) (reverse (cdr (reverse (trans a 1 ocs)))))
coord1
)
coord1 (apply 'append coord1)
pline (vlax-invoke
(vla-get-modelspace
(vla-get-activedocument
(vlax-get-acad-object)
)
)
"addlightweightpolyline"
coord1
)
)
(vla-put-closed pline :vlax-true)
)

(defun c:sqr (/ leg pt)
(if (and
(setq leg (getdist "\nLength of side of square: "))
(setq pt (getpoint "\nSelect centerpoint of square: "))
)
(drawsquare leg pt)
)
(princ)
)

;;; Calculates the cross product of two three-element vectors
(defun MWE:CrossProd (arglst / a b)
(mapcar 'set '(a b) arglst)
(list (- (* (nth 1 a) (nth 2 b)) (* (nth 2 a) (nth 1 b)))
(- (* (nth 2 a) (nth 0 b)) (* (nth 0 a) (nth 2 b)))
(- (* (nth 0 a) (nth 1 b)) (* (nth 1 a) (nth 0 b)))
)
)
Back to top
James Allen
Guest





Posted: Fri Jan 07, 2005 1:30 am    Post subject: Re: AddLightweightPolyline and UCS Reply with quote

Quote:
So, do I need to translate <lst> from UCS to OCS?
Yes. If ename doesn't work, use the view's normal (view direction) in the

trans function.
-->(trans point 1 normal)
Check the docs again, mine say you can use either an ename or extrusion
vector to define an ocs.
Does that get it?
--
James Allen, EIT
Malicoat-Winslow Engineers, P.C.
Columbia, MO


"Jason Piercey" <nomail> wrote in message news:41dc971f$1_2@newsprd01...
Quote:
In the process of fine tuning a routine that generates
the boundary which defines a named view, I thought it
would be nice to include any required transformations
of coordinate systems.

What I have written thus far code wise works fine if I
use the command function to draw the boundary but
when trying to use AddLightweightPolyline things don't
quite work the same.

The help file says that AddLightweightPolyline needs
"The array of 2D OCS coordinates ...."

(vlax-invoke <modelspace> 'AddLightweightPolyline <lst>)

So, do I need to translate <lst> from UCS to OCS? Didn't
see an OCS option in docs on the trans function, other than
using an ename (which doesn't appear to work when passing
a named view's ename)

What am I missing/overlooking?

Back to top
BillZ
Guest





Posted: Fri Jan 07, 2005 7:11 pm    Post subject: Re: AddLightweightPolyline and UCS Reply with quote

Thanks James.

Makes the sqr function a lot more useable.

As always my head is starting to hurt because my understanding of math and OCS doesn't match up to all the information I am taking in. :)

Jason:
You talked about converting from WCS to UCS.
Should work for rectangles drawn in the WCS.

Code:
;01/07/05 Bill Zondlo
;get current ucs matrix and transform entity drawn in WCS.
;
(defun TransObj2Ucs (entnam / *acad* adoc EntObj Matrx NewUCS UCSObj)
  (vl-load-com)
  (setq *acad* (vlax-get-acad-object)
        adoc (vla-get-activedocument *acad*)
        UCSObj (vla-get-UserCoordinateSystems adoc)
        NewUCS (vla-add UCSObj
                 (vlax-3d-point 0 0 0)
                   (vlax-3d-point (getvar "ucsxdir"))
                     (vlax-3d-point (getvar "ucsydir")) "TempUCS")
        Matrx (vla-GetUCSMatrix NewUCS)
        EntObj (vlax-ename->vla-object entnam)
    )
  (vla-transformby EntObj matrx)
  (vla-delete NewUCS)
)


Bill
Back to top
Jason Piercey
Guest





Posted: Mon Jan 10, 2005 8:55 pm    Post subject: Re: AddLightweightPolyline and UCS Reply with quote

Haven't had much of a chance to try any of the
provided suggestions. Thanks to all for the ideas,
I'll try them out when I have sufficient time.

--
Autodesk Discussion Group Facilitator



"Jason Piercey" <nomail> wrote in message news:41dc971f$1_2@newsprd01...

> What am I missing/overlooking?
Back to top
James Allen
Guest





Posted: Wed Jan 12, 2005 8:49 pm    Post subject: Re: AddLightweightPolyline and UCS Reply with quote

Hi Jason,

AddLightweightPolyline expects 2D points. Add this line before the append
in test2:
(setq lst (mapcar '(lambda (a) (reverse (cdr (reverse a)))) lst))

Depending on your application, you may also want to be sure your current ucs
z axis is aligned with the saved view's direction before any trans calls.
If they are not, your lwpolyline will be added in the wrong plane.

James


"Jason Piercey" <Jason AT atreng DOT com> wrote in message
news:41e2e5b1_3@newsprd01...
Quote:
Still not sure what I am missing here but...

Using the attached sample drawing where the
boundary of the named view is the bounding
box of the circle shown.

Test1 works
Test2 does not


; function to create a list of points representing
; the outline of a box based on the center point,
; width and height of the box.
; Arguments:
; [center] - list, 2d point
; [width] - integer or real, width of outline
; [height] - integer or real, height of outline
; returns: list of points
(defun getCornersFromCenter (center width height)
(setq height (/ height 2.0))
(setq width (/ width 2.0))
(list
(mapcar '+ center (list (- width) (- height)))
(mapcar '+ center (list width (- height)))
(mapcar '+ center (list width height))
(mapcar '+ center (list (- width) height))
)
)



; Jon flemming
(defun UCS->OCS (pt)
(trans pt 1 (trans '(0.0 0.0 1.0) 1 0 t)) )



(defun c:test1 (/ document object lst)
(setq document (vla-get-activedocument (vlax-get-acad-object)))
(setq object (vla-item (vla-get-views document) "test"))
(setq
lst
(getCornersFromCenter
(vlax-get object 'center); center is DCS
(vlax-get object 'width)
(vlax-get object 'height))
)
(setq lst (mapcar '(lambda (p) (trans p 0 1)) lst))
(command ".pline") (mapcar 'command lst) (command "c")
(princ)
)



(defun c:test2 (/ document object lst)
(setq document (vla-get-activedocument (vlax-get-acad-object)))
(setq object (vla-item (vla-get-views document) "test"))
(setq
lst
(getCornersFromCenter
(vlax-get object 'center); center is DCS
(vlax-get object 'width)
(vlax-get object 'height))
)
(setq lst (mapcar '(lambda (p) (trans p 0 1)) lst))
(setq lst (mapcar 'ucs->ocs lst))
(setq lst (apply 'append lst))
(setq
object
(vlax-invoke
(vla-get-modelspace document)
'AddLightweightPolyline
lst
)
)
(vla-put-closed object :vlax-true)
(princ)
)


--
Autodesk Discussion Group Facilitator




Back to top
 
Post new topic   Reply to topic    CADForums.net Forum Index -> Customization All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Windows Server DSP VoIP Electronics New Topics
Contact Us
Powered by phpBB