Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Reply
Message 1 of 13
kulfi
817 Views, 12 Replies

ssadd

I have made a selection set and i need to make a copy of this one how can i do.

Thanks

Kulfi
Electronics Engineer

Pind Saudi Arabia



12 REPLIES 12
Message 2 of 13
rkmcswain
in reply to: kulfi

A copy of the selection set or a graphical copy of the objects in the selection set?

If the former, then
(setq a (ssget))
(setq b a)
R.K. McSwain     | CADpanacea | on twitter
Message 3 of 13
Kent1Cooper
in reply to: kulfi


@Kulfi wrote:

I have made a selection set and i need to make a copy of this one how can i do.

Thanks


I assume from the Subject that you mean you want to save another selection set containing the same entities as the first one, rather than to make copies in the drawing of the entities in it.  I'll use ss1 as the name of the set you have already made, and ss2 for the copy.  I expected that this:

 

(setq ss2 ss1)

 

would work, but I find that if I then remove something from ss1 using (ssdel), it is also no longer a part of ss2.  But stepping through ss1 and adding each entity to ss2, for example like this, works:

 

(repeat (setq inc (sslength ss1))

  (ssadd (ssname ss1 (setq inc (1- inc))) ss2)

)

 

Then removing something from ss1 does not also remove it from ss2.

Kent Cooper, AIA
Message 4 of 13
hmsilva
in reply to: kulfi


@Kulfi wrote:

I have made a selection set and i need to make a copy of this one how can i do.

Thanks


Kulfi,

I do agree with Kent1Cooper interpretation of your question, but not with the method.

 

To create a selection set copy, I would use something like

(if (setq ss1 (ssget))
  (progn
    (setq ss2 (ssadd)
	  i -1)
    (repeat (sslength ss1)
        (ssadd (ssname ss1 (setq i (1+ i))) ss2)
) ) )

the

(repeat (setq i (sslength ss1))
  (ssadd (ssname ss1 (setq inc (1- i))) ss2)
  )

  method, will create a selection set with the entities in reversed order, so (nth x ss1) is not the same as (nth x ss2)...

 

HTH

Henrique

EESignature

Message 5 of 13
Kent1Cooper
in reply to: hmsilva


@hmsilva wrote:
...

the

(repeat (setq i (sslength ss1))
  (ssadd (ssname ss1 (setq inc (1- i))) ss2)
  )

  method, will create a selection set with the entities in reversed order, so (nth x ss1) is not the same as (nth x ss2)...

....


Good point -- of course, whether it matters would depend on what use is being made of the sets, but keeping the order the same covers all bases.

 

I had also neglected to put in the (setq ss2 (ssadd)) part, to start the copy set, but then found [in actually trying it -- what a concept!] that without that, it doesn't like being asked to add to it.

Kent Cooper, AIA
Message 6 of 13
hmsilva
in reply to: Kent1Cooper


@Kent1Cooper wrote:
I had also neglected to put in the (setq ss2 (ssadd)) part, to start the copy set, but then found [in actually trying it -- what a concept!] that without that, it doesn't like being asked to add to it.

 Did you tried in a new drawing, or (setq ss2 nil) before?

 

Henrique

EESignature

Message 7 of 13
bhull1985
in reply to: Kent1Cooper

Shouldn't the "I" and the "INC" variables be the same in your example there Kent?

For de/incrementing the counter/selset variable, that is?

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
Message 8 of 13
rkmcswain
in reply to: Kent1Cooper

Kent1Cooper wrote:..... I find that if I then remove something from ss1 using (ssdel), it is also no longer a part of ss2.  But stepping through ss1 and adding each entity to ss2, for example like this, works:

That is some good stuff Kent. Thanks.

I guess both situations could be useful, and it depends on what you are trying to do.

R.K. McSwain     | CADpanacea | on twitter
Message 9 of 13
hmsilva
in reply to: bhull1985


@bhull1985 wrote:

Shouldn't the "I" and the "INC" variables be the same in your example there Kent?

For de/incrementing the counter/selset variable, that is?


Brandon,

It was I who didn't change the inc to i, when I was exemplifying the method, not Kent1Cooper.

Kent1Cooper's code inc variable is always inc, not i...

My bad.

 

Henrique

EESignature

Message 10 of 13
bhull1985
in reply to: hmsilva

Oh I see! Alright, was just noticing that they were using different variables and as such would not pick up the changes within the while loop to the counter var (because they were named differently and the way those incrementors work in loops is by renaming the same variable to keep a running count), if i understand correctly.

🙂

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
Message 11 of 13
Kent1Cooper
in reply to: bhull1985


@bhull1985 wrote:

Shouldn't the "I" and the "INC" variables be the same in your example there Kent? ....


They are both the same [inc] in my original [Message 3] -- it appears hmsilva switched one of them, but not the other, to the i they used, in [mis]quoting mine in Message 4.  [EDIT: ...and now I see hmsilva acknowledged that -- mea culpa for not following the thread further before responding.]

Kent Cooper, AIA
Message 12 of 13
Kent1Cooper
in reply to: hmsilva


@hmsilva wrote:

@Kent1Cooper wrote:
I had also neglected to put in the (setq ss2 (ssadd)) part, to start the copy set, ... without that, it doesn't like being asked to add to it.

 Did you tried in a new drawing, or (setq ss2 nil) before?


I actually tried it in the same drawing in which I had been twiddling with ss1 and ss2, but I used ss3 and ss4 instead, and also [arbitrarily] ss8 and ss9.  In each case, without having yet established an empty selection set under the second name, I got this:

; error: bad argument type: lselsetp nil

 

because there was nothing to add to.

Kent Cooper, AIA
Message 13 of 13
hmsilva
in reply to: Kent1Cooper


@Kent1Cooper wrote:

@hmsilva wrote:

@Kent1Cooper wrote:
I had also neglected to put in the (setq ss2 (ssadd)) part, to start the copy set, ... without that, it doesn't like being asked to add to it.

 Did you tried in a new drawing, or (setq ss2 nil) before?


I actually tried it in the same drawing in which I had been twiddling with ss1 and ss2, but I used ss3 and ss4 instead, and also [arbitrarily] ss8 and ss9.  In each case, without having yet established an empty selection set under the second name, I got this:

; error: bad argument type: lselsetp nil

 

because there was nothing to add to.


Firstly, my apologies Kent.

 

When I first read "without that, it doesn't like being asked to add to it.",  I understood "without that, it does like being asked to add to it." that was the reason I asked if you did try in a new drawing, or (setq ss2 nil) before...

 

My mistake.

 

Henrique

EESignature

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

Post to forums  

Autodesk Design & Make Report

”Boost