Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

selecting object and passing to vla-offset

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
cummins600
2186 Views, 8 Replies

selecting object and passing to vla-offset

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:of8 (/ 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 😎
;(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
)

8 REPLIES 8
Message 2 of 9
Shneuph
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)
Message 3 of 9
cummins600
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:of8 (/ 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 😎
;(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
)

 

 

Message 4 of 9
Hallex
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
Message 5 of 9
cummins600
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.

Message 6 of 9
Shneuph
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)
Message 7 of 9
cummins600
in reply to: Shneuph

Sweet, that got me over the hump. Thanks.

 

(defun c:of8 (/ 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 😎
;(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
)

Message 8 of 9
Kent1Cooper
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, AIA
Message 9 of 9
cummins600
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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost