Author Topic: Problem with the previous selection set  (Read 5302 times)

0 Members and 1 Guest are viewing this topic.

Lupo76

  • Bull Frog
  • Posts: 343
Problem with the previous selection set
« on: July 21, 2016, 01:56:56 AM »
Hello to all,
I hope to be able to explain my problem.
I inserted an object reactor that intervenes every time I move an object.

But by performing the following steps I have a problem:
  • Start the MOVE command and pick any object and conclude the movement
  • Then start again the MOVE command (or COPY / MIRROR) and when prompted to select the objects I type "p" to select the object of the first step.

Unfortunately, the selection group of the second step, contains unwanted objects definitely coming from the reactor processing.
I have noticed that this happens because I used inside the reactor (ssget "X" ......)
How can I avoid this?
I thought I'd save in a variable the selection of the first step group and restore it in the "previous selection set" (the option "P"); but I need your help to do this.

Thanks in advance.
« Last Edit: July 21, 2016, 02:22:16 AM by Lupo76 »

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Problem with the previous selection set
« Reply #1 on: July 21, 2016, 03:13:57 AM »
Try to pass an ssget with filter: (ssget "_P" '((-3 ...))).

Lupo76

  • Bull Frog
  • Posts: 343
Re: Problem with the previous selection set
« Reply #2 on: July 21, 2016, 03:45:57 AM »
Try to pass an ssget with filter: (ssget "_P" '((-3 ...))).

This can not work.
I intend to use the P option using the native commands of the cad (no lisp):

Code: [Select]
Command: MOVE
Select objects: Specify opposite corner: 1 found
Select objects:
Specify base point or [Displacement] <Displacement>:
Specify second point or <use first point as displacement>:

Command: _MOVE
Select objects: p   <----------------------------
1 found

I would that the selection group of the P option is the same as indicated by the user before the reactor and not that of the function (ssget "X" ...) present in the reactor.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Problem with the previous selection set
« Reply #3 on: July 21, 2016, 07:44:55 AM »
The best advice I can give you is: Do not use ssget in your callback function. There must be a better (more efficient) way to achieve what you want.

One way to 'restore' the "_P" selection set is something like this:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / ss1 ss2)
  2.   (setq ss1 (ssget))
  3.   (setq ss2 (ssget "_X"))
  4.   (KGA_Sys_VarStackPush '((grips 0) (highlight 0))) ; Store old and apply new values.
  5.   (sssetfirst nil ss1)
  6.   (ssget "_I")
  7.   (KGA_Sys_VarStackPop) ; Restore old values.
  8.   (princ)
  9. )

But I have my doubts if it will work inside a reactor callback. In BricsCAD using (sssetfirst) is problematic in that context, but maybe this does not apply to AutoCAD.

I am not including the push/pop functions. You probably have your own anyway.

ChrisCarlson

  • Guest
Re: Problem with the previous selection set
« Reply #4 on: July 21, 2016, 07:59:03 AM »
Try to pass an ssget with filter: (ssget "_P" '((-3 ...))).

This can not work.
I intend to use the P option using the native commands of the cad (no lisp):

Code: [Select]
Command: MOVE
Select objects: Specify opposite corner: 1 found
Select objects:
Specify base point or [Displacement] <Displacement>:
Specify second point or <use first point as displacement>:

Command: _MOVE
Select objects: p   <----------------------------
1 found

I would that the selection group of the P option is the same as indicated by the user before the reactor and not that of the function (ssget "X" ...) present in the reactor.

I'm confused, you intend to use native cad commands (possibly scripts?) without LISP but you are using reactors and ssget?

Are you basically moving object A from location A to B, starting the command again and moving object A from location B to C?

Lupo76

  • Bull Frog
  • Posts: 343
Re: Problem with the previous selection set
« Reply #5 on: July 21, 2016, 08:37:14 AM »
I'm confused, you intend to use native cad commands (possibly scripts?) without LISP but you are using reactors and ssget?
Are you basically moving object A from location A to B, starting the command again and moving object A from location B to C?

Yes exactly I need to move the same objects from A to B and then from B to C.
But I could also move the same objects from A to B and then copy them from A to C.
To do this I often use the "P" option to not be forced to re-select all items again.

Lupo76

  • Bull Frog
  • Posts: 343
Re: Problem with the previous selection set
« Reply #6 on: July 21, 2016, 08:44:41 AM »
The best advice I can give you is: Do not use ssget in your callback function. There must be a better (more efficient) way to achieve what you want.

Do you have some practical advice about this?
Here where I use (ssget "X"...)
Code: [Select]
(defun SelWithID (ID typeobj / seleztmp selez ent1 n thexdata)
  (setq selez (ssget "X" (list (cons 0 typeobj)(list -3 (list "MYAPP")))))
  (setq seleztmp (ssadd))
 
  (if selez
    (progn
      (setq n 0)
      (repeat  (sslength selez)
        (setq ent1 (ssname selez n)
              n (1+ n)
        )
        (setq thexdata (cdr (car (cdr (assoc -3 (entget ent1 (list "MYAPP")))))))

        (foreach el thexdata
          (if (= (cdr el) (strcat "ID=" ID))
            (ssadd ent1 seleztmp)
          )
        )
      )
    )
  ) 

  (if (= (sslength seleztmp) 0)
    nil
    seleztmp
  )
)

One way to 'restore' the "_P" selection set is something like this:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / ss1 ss2)
  2.   (setq ss1 (ssget))
  3.   (setq ss2 (ssget "_X"))
  4.   (KGA_Sys_VarStackPush '((grips 0) (highlight 0))) ; Store old and apply new values.
  5.   (sssetfirst nil ss1)
  6.   (ssget "_I")
  7.   (KGA_Sys_VarStackPop) ; Restore old values.
  8.   (princ)
  9. )

But I have my doubts if it will work inside a reactor callback. In BricsCAD using (sssetfirst) is problematic in that context, but maybe this does not apply to AutoCAD.

I use also BricsCAD :-(



I am not including the push/pop functions. You probably have your own anyway.
Can you also send me these functions?

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Problem with the previous selection set
« Reply #7 on: July 21, 2016, 12:18:41 PM »
It seems that you application works with groups of objects that share a common ID. Why don't you store references to all the entities in the group in your Xdata? That would be my approach. For functions that I use to format Xdata see here.
Code: [Select]
(
  ...
  (
    -3
    (
      "MYAPP"
      (1002 . "{")
      ...
      (1002 . "{")
      (1000 . "GROUP_ID")
      (1005 . "ABC123")
      (1002 . "}")
      (1002 . "{")
      (1000 . "OBJECTS_IN_GROUP")
      (1002 . "{")
      (1005 . "...")
      (1005 . "...")
      (1005 . "...")
      (1002 . "}")
      (1002 . "}")
      ...
      (1002 . "}")
    )
  )
)
« Last Edit: July 21, 2016, 12:35:35 PM by roy_043 »

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Problem with the previous selection set
« Reply #8 on: July 21, 2016, 12:35:20 PM »
... I have done a few (but only a few) more tests, and it would seem that code similar to the previously posted function *does* work inside a callback function.
So it is worth trying this:
Code - Auto/Visual Lisp: [Select]
  1. (defun SelWithID (ID typeobj / selezPre seleztmp selez ent1 n thexdata)
  2.   ;; Start new code
  3.   (setq selezPre (ssget "_P"))
  4.   ;; End new code
  5.   (setq selez (ssget "X" (list (cons 0 typeobj)(list -3 (list "MYAPP")))))
  6.   ;; Start new code
  7.   (KGA_Sys_VarStackPush '((grips 0) (highlight 0))) ; Store old and apply new values.
  8.   (sssetfirst nil selezPre)
  9.   (ssget "_I")
  10.   (KGA_Sys_VarStackPop) ; Restore old values.
  11.   ;; End new code
  12.   (setq seleztmp (ssadd))
  13.   (if selez
  14.     (progn
  15.       (setq n 0)
  16.       (repeat  (sslength selez)
  17.         (setq ent1 (ssname selez n)
  18.               n (1+ n)
  19.         )
  20.         (setq thexdata (cdr (car (cdr (assoc -3 (entget ent1 (list "MYAPP")))))))
  21.  
  22.         (foreach el thexdata
  23.           (if (= (cdr el) (strcat "ID=" ID))
  24.             (ssadd ent1 seleztmp)
  25.           )
  26.         )
  27.       )
  28.     )
  29.   )
  30.   (if (= (sslength seleztmp) 0)
  31.     nil
  32.     seleztmp
  33.   )
  34. )
  35.  
  36. (defun KGA_Sys_VarStackPush (lst)
  37.   (setq *sys_varStack*
  38.     (cons
  39.       (mapcar
  40.         '(lambda (a / old)
  41.           (setq old (getvar (car a)))
  42.           (if (cadr a) (setvar (car a) (cadr a)))
  43.           (list (car a) old)
  44.         )
  45.         lst
  46.       )
  47.       *sys_varStack*
  48.     )
  49.   )
  50. )
  51.  
  52. (defun KGA_Sys_VarStackPop ()
  53.   (mapcar
  54.     '(lambda (a)
  55.       (setvar (car a) (cadr a))
  56.     )
  57.     (car *sys_varStack*)
  58.   )
  59.   (setq *sys_varStack* (cdr *sys_varStack*))
  60. )

Edit: Switched back to Lisp-based push/pop functions. Simplified versions of these functions are now included.
« Last Edit: July 21, 2016, 04:48:40 PM by roy_043 »

Lupo76

  • Bull Frog
  • Posts: 343
Re: Problem with the previous selection set
« Reply #9 on: July 21, 2016, 01:07:14 PM »
It seems that you application works with groups of objects that share a common ID. Why don't you store references to all the entities in the group in your Xdata? That would be my approach. For functions that I use to format Xdata see here.

Your advice is very interesting and definitely will greatly increase the performance of my application!
It will take a long time to implement it but I'm sure in the next few weeks I will do this ;-)

Lupo76

  • Bull Frog
  • Posts: 343
Re: Problem with the previous selection set
« Reply #10 on: July 21, 2016, 01:13:19 PM »
As you can see I have used acet-sysvar* functions instead of the previous push/pop functions. These acet-sysvar* functions are built-in functions in BricsCAD.

My application must be compatible with AutoCAD 2011 and higher, and also with BricsCAD V14 and higher.
If I remember correctly the functions "acet-sysvar*" is inserted in the Express Tools in AutoCAD, so in theory if the user has not installed Express Tools your solution does not work in AutoCAD: right?
Is there some way to make it work even in AutoCAD without Express Tools?

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Problem with the previous selection set
« Reply #11 on: July 21, 2016, 04:46:15 PM »
Is there some way to make it work even in AutoCAD without Express Tools?
I have edited post #8.

Lupo76

  • Bull Frog
  • Posts: 343
Re: Problem with the previous selection set
« Reply #12 on: July 22, 2016, 08:57:21 AM »
Is there some way to make it work even in AutoCAD without Express Tools?
I have edited post #8.

Hello Roy,
with your help I solved the problem.
However I have not used functions "KGA_Sys_VarStackPush" and "KGA_Sys_VarStackPop".
Why did you have entered these functions?
I see no reason to use them.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Problem with the previous selection set
« Reply #13 on: July 22, 2016, 09:21:55 AM »
with your help I solved the problem.
I am glad to hear that.

However I have not used functions "KGA_Sys_VarStackPush" and "KGA_Sys_VarStackPop".
Why did you have entered these functions?
To avoid highlighting and gripping the 'sssetfirst' selection set. You may not notice any effect on small sets (although in BricsCAD I do detect an extra 'blink') but even then this will have an impact on speed.

Lupo76

  • Bull Frog
  • Posts: 343
Re: Problem with the previous selection set
« Reply #14 on: July 22, 2016, 10:35:26 AM »
To avoid highlighting and gripping the 'sssetfirst' selection set. You may not notice any effect on small sets (although in BricsCAD I do detect an extra 'blink') but even then this will have an impact on speed.

You're right!
now I understand what you did!
Thank you.