Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Valued Contributor
cummins600
Posts: 97
Registered: ‎03-24-2004
Message 1 of 9 (856 Views)
Accepted Solution

selecting object and passing to vla-offset

856 Views, 8 Replies
02-29-2012 09:01 AM

Hi, I'm trying to complete the code to select a p-line on layer G-POLY-GSF w/o asking for input. this (setq ent (ssget "X" (list (cons 8 "G-POLY-GSF"))) dosen't seem to work. What I'm I missing here?

 

(defun c:smileysurprised:f8 (/ ent dist obj)
(vl-load-com)
(setq ent (car (entsel "\nSelect line to offset: "))
;(setq ent (ssget "X" (list (cons 8 "G-POLY-GSF")))
)
(setq dist 8)
;(initget (+ 1 2 4 64))
;(setq dist (getdist "\nEnter offset distance: "))
;(initget (+ 2 4) "Yes No")
(setq obj (vlax-ename->vla-object ent))
;(vla-offset obj dist)
(vla-offset obj (* dist -1));outside
)

Valued Mentor
Shneuph
Posts: 349
Registered: ‎11-26-2007
Message 2 of 9 (850 Views)

Re: selecting object and passing to vla-offset

02-29-2012 09:19 AM in reply to: cummins600

 (setq ent (ssget "X" (list (cons 8 "G-POLY-GSF"))) creates a selection set.. (vlax-ename->vla-object needs an entity name.  You can convert the selection set to a list of entities or iterate through it using (ssname ent [number])

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
Valued Contributor
cummins600
Posts: 97
Registered: ‎03-24-2004
Message 3 of 9 (833 Views)

Re: selecting object and passing to vla-offset

02-29-2012 11:50 AM in reply to: Shneuph

I'm really getting trip'd up with this one. Would I be on the right track with this (setq obj (vlax-ename->vla-object (ssname ent)))?

 

(defun c:smileysurprised:f8 (/ ent dist obj)
(vl-load-com)
;(setq ent (car (entsel "\nSelect line to offset: "))
(setq ent (ssget "X" (list (cons 8 "G-POLY-GSF")))
)
(setq dist 8)
;(initget (+ 1 2 4 64))
;(setq dist (getdist "\nEnter offset distance: "))
;(initget (+ 2 4) "Yes No")
;;; (setq obj (vlax-ename->vla-object ent))
(setq obj (vlax-ename->vla-object (ssname ent)))
;(vla-offset obj dist)
(vla-offset obj (* dist -1));outside
)

 

 

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 4 of 9 (831 Views)

Re: selecting object and passing to vla-offset

02-29-2012 11:57 AM in reply to: cummins600

Take a look closely at this code

sorry didn't add some explanation, see Help

{code}

(defun C:test (/ adoc ans axss ffobj fobj offd sfobj sobj ss)
   (setq adoc
   (vla-get-activedocument
     (vlax-get-acad-object)
   )
   )

   (if (setq ss (ssget))
     (progn
       (not (vl-catch-all-error-p
       (vl-catch-all-apply 'vla-clear (list (vla-get-pickfirstselectionset adoc)))
     )
       )

       (sssetfirst ss ss)
       (setq axss (vla-get-pickfirstselectionset adoc))

       (setq offd (getdist "\nOffset distance :"))
       (initget "Yes No")
       (setq ans (getkword "\nBoth sides? [Yes/No] <Yes>:"))
       (vlax-for obj axss
  (cond ((eq "No" ans)

  (setq fobj  (vla-offset obj offd)
        ffobj (car (vlax-safearray->list
       (vlax-variant-value fobj)
     )
       )
  )
  (vlax-put ffobj 'color 130)
        )
        (T
  (setq fobj  (vla-offset obj offd)
        ffobj (car (vlax-safearray->list
       (vlax-variant-value fobj)
     )
       )
  )
  (vlax-put ffobj 'color 71)
  (setq sobj  (vla-offset obj (- offd))
        sfobj (car (vlax-safearray->list
       (vlax-variant-value sobj)
     )
       )
  )
  (vlax-put sfobj 'color 32)
        )
  )
       )
     )
   )
   (princ)
 )

{code}

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Valued Contributor
cummins600
Posts: 97
Registered: ‎03-24-2004
Message 5 of 9 (827 Views)

Re: selecting object and passing to vla-offset

02-29-2012 12:10 PM in reply to: Hallex

Seems like this shouldn't be too hard, but it's kicking me good. It's just not clicking for me.

Valued Mentor
Shneuph
Posts: 349
Registered: ‎11-26-2007
Message 6 of 9 (818 Views)

Re: selecting object and passing to vla-offset

02-29-2012 01:06 PM in reply to: cummins600

cummins600 wrote:

I'm really getting trip'd up with this one. Would I be on the right track with this (setq obj (vlax-ename->vla-object (ssname ent)))?

 



Yes, your'e on the right rack, but (ssname) requires 2 arguments...  The selection set and the index of the item

 

http://docs.autodesk.com/ACD/2011/ENU/filesALR/WS1a9193826455f5ff1a32d8d10ebc6b7ccc-6935.htm

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
Valued Contributor
cummins600
Posts: 97
Registered: ‎03-24-2004
Message 7 of 9 (811 Views)

Re: selecting object and passing to vla-offset

02-29-2012 01:44 PM in reply to: Shneuph

Sweet, that got me over the hump. Thanks.

 

(defun c:smileysurprised:f8 (/ ent dist obj)
(vl-load-com)
;(setq ent (car (entsel "\nSelect line to offset: "))
(setq ent (ssget "X" (list (cons 8 "G-POLY-GSF")))
)
(setq dist 8)
;(initget (+ 1 2 4 64))
;(setq dist (getdist "\nEnter offset distance: "))
;(initget (+ 2 4) "Yes No")
;;; (setq obj (vlax-ename->vla-object ent))
(setq obj (vlax-ename->vla-object (ssname ent 0)))
;(vla-offset obj dist)
(vla-offset obj (* dist -1));outside
)

*Expert Elite*
Kent1Cooper
Posts: 5,389
Registered: ‎09-13-2004
Message 8 of 9 (808 Views)

Re: selecting object and passing to vla-offset

02-29-2012 01:52 PM in reply to: cummins600

cummins600 wrote:

I'm really getting trip'd up with this one. Would I be on the right track with this (setq obj (vlax-ename->vla-object (ssname ent)))?

....

(setq ent (ssget "X" (list (cons 8 "G-POLY-GSF")))
....

(setq obj (vlax-ename->vla-object (ssname ent)))
....

(vla-offset obj (* dist -1));outside
....


As Schneuph posted:

 

If there's only going to be one thing in the selection set, you would use index number 0:

(setq obj (vlax-ename->vla-object (ssname ent 0)))
 

In addition to that, you could also simplify some things:
 

If the Layer is known, you can shorten the (ssget) filter list with a dotted-pair list:

  (setq ent (ssget "X" '((8 . "G-POLY-GSF"))))

[but maybe that will ultimately be a Layer name taken from a selected object or something, put into a variable, in which case you would need to keep the (list (cons... format].
 

And you can make a negative number more simply than by multiplying it by -1:

(vla-offset obj (- dist));outside

Kent Cooper
Valued Contributor
cummins600
Posts: 97
Registered: ‎03-24-2004
Message 9 of 9 (806 Views)

Re: selecting object and passing to vla-offset

02-29-2012 01:57 PM in reply to: Kent1Cooper

Cool. In this case, there will be only one selection to select from so I think the 0 will work fine.

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.