Author Topic: Single ssget with filters  (Read 4317 times)

0 Members and 1 Guest are viewing this topic.

SPDCad

  • Bull Frog
  • Posts: 453
Single ssget with filters
« on: December 07, 2004, 12:39:17 PM »
I am looking for a way to have the user select an xref only entity, and if the user does not pick one, he is prompted till he does.  If a Nil variable < hit enter> is returned the lisp will end.

I used following code to try and complete the task,  but unfortunetly the
code will return any entity type (ignoring the filters list).  I have a few other ideas which I am still working on, but maybe I can get other ideas on how to preform the task.

Code: [Select]
(setq ARG (ssget ":S" '((100 . "AcDbBlockReference")) ) )

Any help would be greatly appreciated.... :?:
AutoCAD 2010, w/ OpenDCL

visit: http://reachme.at/spd_designs

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Single ssget with filters
« Reply #1 on: December 07, 2004, 01:42:48 PM »
Here's one way. If the user hits enter or the spacebar or selects nothing it exits, otherwise it cycles until an xref is selected:
Code: [Select]

(defun pick_xref (/ ans tmp doc)
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (while (not tmp)
    (and (setq ans (entsel "\nSelect an Xref: "))
(setq tmp (vlax-ename->vla-object (car ans)))
(if (eq (vla-get-objectname tmp) "AcDbBlockReference")
  t
  (setq tmp nil)
  )
(if (eq (vla-get-isxref (vla-item (vla-get-blocks doc) (vla-get-name tmp))) :vlax-true)
  t
  (setq tmp nil)
  )
)
    (if (not ans)
      (setq tmp "")
      )
    )
  (if (and tmp
  (not (eq tmp ""))
  )
    (car ans)
    nil
    )
  )

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Single ssget with filters
« Reply #2 on: December 07, 2004, 02:30:08 PM »
What about this method.

Code: [Select]

(defun get-utilobj ()
(vla-get-utility
 (vla-get-activedocument
(vlax-get-acad-object)
)
 )
)

  (defun obj-select (msg / obj pt)
(if
 (not
(vl-catch-all-error-p
 (vl-catch-all-apply
'vlax-invoke-method
(list (get-utilobj) 'GetEntity 'obj 'pt (vlax-make-variant msg))
)
 )
); not
  obj
  )
)

(setq obj (obj-select "\nSelect Xref: "))
(while
  (not
(vlax-property-available-p obj 'Path)
)
   (setq obj (obj-select "\nSelect Xref <enter to quit>: "))
   )
 
TheSwamp.org  (serving the CAD community since 2003)

whdjr

  • Guest
Single ssget with filters
« Reply #3 on: December 07, 2004, 02:57:05 PM »
Here's my solution:

Load it and type xrefs.
Code: [Select]
(defun isxref (blockname)
  (= 4
     (logand
       (dxf 70 (entget (tblobjname "block" blockname)))
       4
     )
  )
)

(defun ssnames (selection_set / num lst)
  (repeat (setq num (sslength selection_set))
    (setq num (1- num)
 lst (cons (ssname selection_set num) lst)
    )
  )
  lst
)

(defun dxf (gcode elist)
  (cdr (assoc gcode elist))
)

(defun c:xrefs (/ ss blk lst)
  (if (setq ss (ssget '((2 . "*")
(100 . "*BLOCK*")
(-4 . "<NOT")
(0 . "HATCH")
(-4 . "NOT>")
      )
      )
      )
    (vl-remove-if-not
      '(lambda (x)
(if (isxref (setq blk (dxf 2 (entget x))))
  (setq lst (cons blk lst))
)
       )
      (ssnames ss)
    )
  )
  lst
)

David Bethel

  • Swamp Rat
  • Posts: 656
Single ssget with filters
« Reply #4 on: December 07, 2004, 03:08:59 PM »
Code: [Select]
(defun get1xref (/ ss)
  (while (or (not ss)
             (> (sslength ss) 1)
             (/= (logand (cdr (assoc 70 (tblsearch "BLOCK" (cdr (assoc 2 (entget (ssname ss 0))))))) 4) 4))
         (setq ss (ssget '((0 . "INSERT")))))
 (ssname ss 0))


-David
R12 Dos - A2K

SPDCad

  • Bull Frog
  • Posts: 453
Single ssget with filters
« Reply #5 on: December 07, 2004, 03:23:21 PM »
Thanks guys for all the Help, it was apprecited.
AutoCAD 2010, w/ OpenDCL

visit: http://reachme.at/spd_designs

David Bethel

  • Swamp Rat
  • Posts: 656
Single ssget with filters
« Reply #6 on: December 07, 2004, 03:31:42 PM »
PS:  I'm not a big fan of exiting a program in the manner you described.  It can lead to major headaches IMO.  -David
R12 Dos - A2K

SPDCad

  • Bull Frog
  • Posts: 453
Single ssget with filters
« Reply #7 on: December 07, 2004, 03:33:56 PM »
Quote from: David D Bethel
PS:  I'm not a big fan of exiting a program in the manner you described.  It can lead to major headaches IMO.  -David


I not a big fan of exiting a program by just hitting enter either, but that is what the client wants and what he wants he gets.
AutoCAD 2010, w/ OpenDCL

visit: http://reachme.at/spd_designs

SMadsen

  • Guest
Re: Single ssget with filters
« Reply #8 on: December 08, 2004, 08:23:17 AM »
SPDCad,
Just to add some clarification to your initial post, it's not because the :S method can't accept filter lists but that no SSGET method is able to filter by class names.

(ssget ":S" '((0 . "INSERT"))) will work just fine. INSERTs don't contain xref information, so you'll of course have to verify the result after selecting. For example something like ..

Code: [Select]
(defun getSingleXRef (/ sset ent)
  (while (not sset)
    (cond
      ((setq sset (ssget ":S" '((0 . "INSERT"))))
       (if (< (cdr (assoc 70 (tblsearch "BLOCK"
                     (cdr (assoc 2 (entget (setq ent (ssname sset 0)))))))) 4)
          (setq sset nil)
         ent
       )
      )
    )
  )
)

David Bethel

  • Swamp Rat
  • Posts: 656
Single ssget with filters
« Reply #9 on: December 08, 2004, 12:27:30 PM »
Stig,

I don't think the (< (cdr (assoc 70 ... will work.

The 64 bit should be set if the BLOCK is referenced as a plain INSERT.  -David
R12 Dos - A2K

SMadsen

  • Guest
Single ssget with filters
« Reply #10 on: December 08, 2004, 12:41:14 PM »
David, I agree that LOGAND is the right method (didn't really see your code .. or I would have commented on the similarity :) )

I've never seen bit 6 in action for any table entry, though.

David Bethel

  • Swamp Rat
  • Posts: 656
Single ssget with filters
« Reply #11 on: December 08, 2004, 01:19:02 PM »
Stig,

It looks like that the 64 bit has been dropped somewhere along th line.  This is from R13 help files


Code: [Select]
BLOCK group codes

Group codes Description

5 Handle
100 Subclass marker (AcDbEntity)
8 Layer name (fixed)
100 Subclass marker (AcDbBlockBegin)
2 Block name
70 Block-type bit-coded flags
 1 = This is an anonymous block generated by hatching, associative dimensioning, other internal operations, or an application
 2 = This block has attribute definitions
 4 = This block is an external reference (xref)
 8 = This block is an xref overlay
16 = This block is externally dependent
32 = This is a resolved external reference, or dependent of an external reference (ignored on input)
64 = This definition is referenced (ignored on input)

10 DXF: X value of block base point   Application: Block base point
20, 30 DXF only: Y and Z values of block base point
3 Block name
1 Xref path name (if the block is an xref) (optional)



Copyright (c) 1995 Autodesk, Inc.


-David
R12 Dos - A2K

Anonymous

  • Guest
Re: Single ssget with filters
« Reply #12 on: December 08, 2004, 03:13:07 PM »
Thanks for the tip, SMadsen. After I posted the intial code, I rethought the process and came up with something very simlar to the code you posted.