Author Topic: Hiding entities  (Read 3200 times)

0 Members and 1 Guest are viewing this topic.

csgoh

  • Newt
  • Posts: 176
Hiding entities
« on: June 24, 2005, 10:42:55 PM »
I am writing a routine in Vlisp/ActiveX but am stucked midway and hope to get some help.

My routine is as follows;_

1)   Prompt the user to select a closed polyline
2)   Routine then selects all the entities within the polyline using the
      selectbypolygon method.
3)   So what is the method in order that the selected closed polyline is not
      selected in ActiveX. In the old lisp I use the (entdel entity) before
      selecting the entities inside the polyline and then repeat the (entdel
      entity) after that.
4)   I tried using the (Vlax-put-property obj 'Visible :vlax-false) but it still
     select the closed polyline.
   
Thanks.

csgoh

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Re: Hiding entities
« Reply #1 on: June 25, 2005, 01:00:55 AM »
Quote from: csgoh
I am writing a routine in Vlisp/ActiveX but am stucked midway and hope to get some help.

4)   I tried using the (Vlax-put-property obj 'Visible :vlax-false) but it still
     select the closed polyline.
   
Thanks.

csgoh
The problem stems from using the incorrect integer as I described in your other post. Here's an example of how this should work.
Code: [Select]

(defun getPolySS (/ *doc* ss ent obj coords 3dcoords)
  (setq *doc* (vla-get-activedocument (vlax-get-acad-object)))
  (vl-catch-all-apply 'vla-add
    (list (vla-get-selectionsets *doc*) "Poly_ss"))
  (setq ss (vla-item (vla-get-selectionsets *doc*) "Poly_ss"))
  (vla-clear ss)
  (setq ent (car (entsel "\nSelect polygon: "))
obj (vlax-ename->vla-object ent)
coords (vlax-get obj 'coordinates))
  (while coords
    (setq 3dcoords (append 3dcoords (list (car coords) (cadr coords) 0.0))
 coords (cddr coords))
    )
  (vlax-invoke ss 'selectbypolygon acselectionsetwindowpolygon 3dcoords)
  ss
  )

this will return your selection set.

Amsterdammed

  • Guest
Hiding entities
« Reply #2 on: June 25, 2005, 08:19:30 AM »
Jeff,
is there somewhere a list with all the vl, vlax and so on vlisp extensions? Like; what is what? I want to get more into it, it just seems better than the lisp expressions only.
Thanks, Bernd :?:

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Hiding entities
« Reply #3 on: June 25, 2005, 08:49:02 AM »
Quote from: Amsterdammed
is there somewhere a list with all the vl, vlax and so on vlisp extensions?

This could be a good start:
http://www.dsxcad.com/book/index.html

Cheers
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18

daron

  • Guest
Hiding entities
« Reply #4 on: June 26, 2005, 12:27:21 AM »
Bernd, if you look in the developer help files under ActiveX/VBA... down toward the bottom, you will find many of the functions. They're written for VBA, so you'll have to figure out how to make it work. If you grab CAB's plot tabs routine in the Show Your Stuff forum, you can learn a lot from it.

csgoh

  • Newt
  • Posts: 176
Hiding entities
« Reply #5 on: June 26, 2005, 03:51:06 AM »
Thanks Jeff.  Looked into the vbaide and found WP=6, CP=7 & Fence=2.

Your sample for selectbywindowpolygon is great provided there are no entities crossing the initial polygon selected. My intention is to use the crossingpolygon method to select everything inside and crossing the polygon but not the polygon selected. Using the (entdel entity) solves the problem but I want to learn the Vlisp/ActiveX method. Is there a methood in ActiveX that works exactly like the (entdel entity).

csgoh.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Hiding entities
« Reply #6 on: June 26, 2005, 09:56:51 AM »
Check this out.
Something created by our resident genius. :)

http://www.theswamp.org/phpBB2/viewtopic.php?p=62997#62997
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Hiding entities
« Reply #7 on: June 26, 2005, 01:50:55 PM »
Quote from: csgoh
Using the (entdel entity) solves the problem but I want to learn the Vlisp/ActiveX method. Is there a methood in ActiveX that works exactly like the (entdel entity).

You're welcome.
IMO, folks learning VLisp/Activex take it too far (myself included). If you have something that works, why not use it? In this case, my code is already obtaining the <ename> (granted, I reset the symbol for it the vla-object, but it would be simple to use a different symbol) so use the (entdel) method before & after the selection process. Otherwise, you could iterate the selection set and remove the object from it...but this would undoubtedly take a bit more time, although probably not noticable to the user.

Again, IMO, if you REALLY want to use ALL ActiveX methods & properties then dump lisp and go to VBA. But when using lisp, use ALL of the available tools, not just those applicable to ActiveX......of course, I learned this just as you are now, through lots of trial & error and posting questions.   :D

csgoh

  • Newt
  • Posts: 176
Hiding entities
« Reply #8 on: June 26, 2005, 09:10:29 PM »
Maybe I am overzealous in trying to write a routine that is ALL ActiveX which may not necessary better than the old lisp. However, your explanation is noted with thanks.

csgoh

SMadsen

  • Guest
Hiding entities
« Reply #9 on: June 27, 2005, 05:42:21 AM »
Quote from: csgoh
Thanks Jeff.  Looked into the vbaide and found WP=6, CP=7 & Fence=2.

Your sample for selectbywindowpolygon is great provided there are no entities crossing the initial polygon selected. My intention is to use the crossingpolygon method to select everything inside and crossing the polygon but not the polygon selected. Using the (entdel entity) solves the problem but I want to learn the Vlisp/ActiveX method. Is there a methood in ActiveX that works exactly like the (entdel entity).

csgoh.

As you describe it, using ENTDEL on the boundary object before doing a selection will exclude it from the selection. However, if the routine fails between ENTDEL's, there's a chance you'll loose the object. A much better way is to use SSDEL, which will remove the boundary object after doing the selection. It doesn't affect the object in any way, - only the selection set.

Similarly in ActiveX, you'd use the RemoveItems method to accomplish the same task. A considerably more complicated way than dealing with the SS-functions.

csgoh

  • Newt
  • Posts: 176
Hiding entities
« Reply #10 on: June 28, 2005, 11:48:36 AM »
Thanks Stig.

I have tried using the vla-RemoveItems as you described but got an error: bad argument type VLA-OBJECT #<variant 8 ss1>
before the vla-removeitems. Where have I done wrong??
Thanks in advance.


Snippet of my code
Code: [Select]

;; ===========================================================
;; Convert a list into a safearray
;;
(defun ListToSafearray (symVariableType lstValues / safValues)
 (setq safValues (vlax-make-safearray symVariableType
                  (cons 0 (1- (length lstValues)))))
 (vlax-safearray-fill safValues lstValues)
) ;listToSafeArray


;;
;; GetObjectsByPolygon
;; Mode? = 2 = acSelectionSetfence
;; Mode? = 6 = acSelectionSetWindowPolygon
;; Mode? = 7 = acSelectionSetCrossingPolygon
;; PointList list of coords
;; whatobjects = filtered objects
;; Returns a list of the filtered objects
;; BaseObj = nil Do not remove from selection set
;; BaseObj = baseobj - to remove it from the selection set
;;
(defun wg:GetObjectsByPolygon-list
                               (ActivedocumentObj whatobjects PointList mode?
                                BaseObj
                                / objects-list   obj
                                ssets ss1 ssobj
                                filter_codelist filter_valuelist
                                filter_code    filter_value
                                filter_what? filter_what?STR
                               )

 (setq objects-list nil
        obj          nil

  ) ;_ end of setq
  (setq ssets (vla-get-selectionsets ActivedocumentObj))
  (setq ss1 (vlax-make-variant "ss1"))
  (if (vl-catch-all-error-p
        (vl-catch-all-apply 'vla-item (list ssets ss1))
      )
    (setq ssobj (vla-add ssets ss1))
    (progn
      (vla-delete (vla-item ssets ss1))
      (setq ssobj (vla-add ssets ss1))
    )
  ) ;_if
  (setq filter_codelist  (mapcar '(lambda (x) (car x)) whatobjects)
        filter_valuelist (mapcar '(lambda (x) (cdr x)) whatobjects)
        filter_code      (vlax-make-safearray
                           vlax-vbinteger
                           (cons 0 (1- (length filter_codelist)))
                         )

        filter_value     (vlax-make-safearray
                           vlax-vbvariant
                           (cons 0 (1- (length filter_valuelist)))
                         )
  )
  (vlax-safearray-fill filter_code filter_codelist)
  (vlax-safearray-fill filter_value filter_valuelist)

  (if (= (car filter_valuelist) "<OR")
    (setq filter_what? (reverse(cdr (reverse (cdr filter_valuelist)))))
    (setq filter_what? filter_valuelist)
  )
  (setq filter_what? (subst "BLOCK" "INSERT" filter_what?))
  (setq filter_what?STR (nth 0 filter_what?)
        filter_what? (cdr filter_what?)
  )
  (while filter_what?
   (setq filter_what?STR (strcat filter_what?STR " " (car filter_what?))
         filter_what? (cdr filter_what?)
   )
  );while
;  (prompt "\nPls select ")(princ (vl-sort filter_what? '<))
;  (princ " objects....")
  (dos_msgbox (strcat "Selecting only "  filter_what?STR " objects...." )
              "OBJECTS ENTITY SELECTION " 1 3 1
  )

; (cond
;  ((= mode? 0)
;    (vla-SelectByPolygon ssobj acSelectionSetFence PointList
;           filter_code filter_value)
;  )
;  ((= mode? 1)
;    (vla-SelectByPolygon ssobj acSelectionSetWindowPolygon PointList
;           filter_code filter_value)
;  )
;  ((= mode? 2)
;    (vla-SelectByPolygon ssobj acSelectionSetCrossingPolygon PointList
;           filter_code filter_value)
;  )
; );cond

    (vla-SelectByPolygon ssobj mode? PointList filter_code filter_value)
;;
;; Remove polygon from selection set
;; BaseObj = nil do not remove
;;
    (if BaseObj
     (progn
     (vla-RemoveItems ss1 (vlax-make-variant
                              (listToSafeArray 9 (list BaseObj)) )
      )
     )
    )
  (if (> (vla-get-count ssobj) 0)
    (progn
      (setq no-ent nil)
      (setq i (- 1))
      (repeat (vla-get-count ssobj)
        (setq
          obj (vla-item ssobj
                        (vlax-make-variant (setq i (1+ i)))
              )                         ;end of vla-item
          objects-list (append objects-list (list obj))
        ) ;_ end of setq
      )                                 ;end of repeat
    )                                   ;end of progn
  ) ;_ end of if
  objects-list
) ;_ wg:GetObjectsByPolygon-list
 


(defun C:PolyDir ( / 2pi e coordsClosed acadObj ActivedocumentObj BaseObj
                     FilterPoints-list MainPolygonVertex-list  
                     Allobjects-list coordsOpen BaseObj2D obj obj2D
                     IntersectionPoints-list inxnvertex-list
                 )
   (vl-load-com)
   (setq acadObj           (vlax-get-acad-object)
        ;; acad Object
        ActivedocumentObj (vla-get-Activedocument acadObj)
        ;; the current dwg
   );setq
   (setvar "errno" 0)
   (setq 2pi (* pi 2))
   (while (/= (getvar "errno") 52)
;;
;; (wg:GetClockwisePolygonCoords entity (list of entity names) [T or nil])
;; T = selected polyline must be closed
;; nil = no need for closed polyline
;;
      (cond
;;
;; coordsClosed = list of vertices 3D coords of the polyline
;;        = ((x0 y0 z0)(x1 y1 z1)(x2 y2 z2)........ (xn yn zn)(x0 y0 z0))
;; coordsOpen = list of vertices 3D coords of the polyline
;;        = ((x0 y0 z0)(x1 y1 z1)(x2 y2 z2)........ (xn yn zn))
;; as in (vlax-get-property obj 'Coordinates)
;;
       ((setq coordsClosed (wg:GetClockwisePolygonCoords
                      (setq e (car (entsel "\nSelect a polyline: ")))
                      '("LWPOLYLINE" "POLYLINE") T))

       (setq BaseObj    (vlax-ename->vla-object e) ; the polyline
              coordsOpen (reverse (cdr(reverse coordsClosed)))
              Allobjects-list '() ; all objects
              IntersectionPoints-list '() ; Intersection points
              InxnVertex-list '()   ; Param of intersection point
        )
;;
;; make variant of doubles in array
;; 5 = vlax-vbDouble
;; (wg:GetSingle3D-list Coords nil)
;; nil ==> z coord = 0.000
;; T ==> z value coord
;;
         (setq FilterPoints-list (vlax-make-variant
                                   (listToSafeArray 5
                                     (wg:GetSingle3D-list CoordsClosed nil)
                                 )))
;;
;; Turn off selected polyline :vlax-false
;;
;;         (vlax-put-property BaseObj 'Visible :vlax-false)
;          (entdel e) ;  delete the selected polyline
;;
;; 2 = mode? acSelectionSetFence
;; 6 = mode? acSelectionSetWindowPolygon
;; 7 = mode? acSelectionSetCrossingPolygon
;; Select Filtered Objects - ie Lines only
;; BaseObj - nil is do not want to Remove the polygon from the selection set
;; BaseObj - baseobj if it is to be removed from the selection set.
;;  (wg:GetObjectsByPolygon-list ActivedocumentObj
;;    (list '(0 . "LINE")) FilterPoints-list 7 BaseObj
;;  )
;;
            (setq AllObjects-list
             (wg:GetObjectsByPolygon-list ActivedocumentObj
              (list '(0 . "LINE")) FilterPoints-list 7 BaseObj
             )
            ) ; setq
;;
;; Turn back on the selected polyline :vlax-true
;;
;         (vlax-put-property BaseObj 'Visible :vlax-true)
;;
;          (entdel e) ; restore the selected polyline

;          (if (member BaseObj Allobjects-list)

etc


Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Hiding entities
« Reply #11 on: June 28, 2005, 04:30:44 PM »
Holy massive amounts of coding Batman!

All that work to create a list of objects inside a pline?

When working with ActiveX selection sets there is no need to step through as you do a standard ss with (while) or (repeat). (vlax-for ent ss ....) cycles through it nice & clean, returning each vla-object in turn.

And since you are only creating a list of the objects, just check for the objectid while iterating the ss and don't add the polygon's object to the list, rather than trying to remove it from the ss.

<deleted stuff about vlisp vs lisp>

I will mention that since you are learning, experiment with (vlax-invoke) (vlax-get) & (vlax-put). You will find that many of the methods and properties that would normally require the variants & safearrays will accept plain lists which are far easier to track and use. Not all support this approach, but I sure find it easier to work with.

whdjr

  • Guest
Hiding entities
« Reply #12 on: June 29, 2005, 12:33:32 PM »
Quote from: Jeff_M
Holy massive amounts of coding Batman!

All that work to create a list of objects inside a pline?

When working with ActiveX selection sets there is no need to step through as you do a standard ss with (while) or (repeat). (vlax-for ent ss ....) cycles through it nice & clean, returning each vla-object in turn...

(vlax-map-collection) works wonders too.
Herr's a small example:
Code: [Select]
(defun test (/ adoc ssets objs pt1 pt2 str)
  (and
    (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
    (setq ssets (vla-get-selectionsets adoc))
    (if
      (eq ""
 (setq str (getstring "\nEnter name for selection set <ss>: "))
      )
       (setq str "ss")
       str
    )
    (if (vl-catch-all-error-p
 (vl-catch-all-apply 'vla-add (list ssets str))
)
      (prompt "\nThe SelectionSet Name is already used.")
      T
    )
    (not (initget (+ 1 8 32)))
    (setq pt1 (getpoint "\nPick first corner of selection window: "))
    (not (initget (+ 1 8 32)))
    (setq
      pt2 (getcorner pt1 "\nPick second corner of selection window: ")
    )
    (mapcar 'set '(pt1 pt2) (mapcar 'vlax-3d-point (list pt1 pt2)))
    (not (vla-select (vla-item ssets str) acSelectionSetCrossing pt1 pt2)
    )
    (vlax-map-collection
      (vla-item ssets str)
      '(lambda (x) (setq objs (cons x objs)))
    )
    (mapcar 'princ objs)
  )
)