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
)
Solved! Go to Solution.
Solved by Shneuph. Go to Solution.
(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])
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
)
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'~
Seems like this shouldn't be too hard, but it's kicking me good. It's just not clicking for me.
@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
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
)
@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
Cool. In this case, there will be only one selection to select from so I think the 0 will work fine.