Trying to select the last created objects from commands like (COPY,MIRROR,....,etc) by using the "selresult.lsp" file

Trying to select the last created objects from commands like (COPY,MIRROR,....,etc) by using the "selresult.lsp" file

Ahmed_204
Enthusiast Enthusiast
556 Views
7 Replies
Message 1 of 8

Trying to select the last created objects from commands like (COPY,MIRROR,....,etc) by using the "selresult.lsp" file

Ahmed_204
Enthusiast
Enthusiast

Trying to select the last created objects from commands like (COPY,MIRROR,....,etc) by using the "selresult.lsp" file attached below but its not working with dynamic blocks as shown in the attached video and giving the below error.

 

"Which one of these do you want to select? [0-MOVE/1-COPY/2-COPY/3-MOVE/4-COPY/]<0>: 4
; error: bad argument type: lselsetp nil"

 

@Kent1Cooper @BeekeeCZ @komondormrex @paullimapa @Sea-Haven your help will be appreciated.

 

Thanks in advance

 

0 Likes
557 Views
7 Replies
Replies (7)
Message 2 of 8

calderg1000
Mentor
Mentor

Regards @Ahmed_204 

The routine works fine. To clean up previous actions, delete the block group, then copy it, and then proceed normally with the copy.

It should look like this:

calderg1000_0-1698001975605.png

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

0 Likes
Message 3 of 8

komondormrex
Mentor
Mentor

check the (select_last_added) function to select and get gripped last added object(s) to the database.

 

;***********************************************************************************************************************************

;	komondormrex, oct 2023
;	(select_last_added) function lets select and get gripped last added object(s) to the database

;***********************************************************************************************************************************

(if (/= 'vlr-acdb-reactor  (type object_appended_reactor))
	(setq object_appended_reactor (vlr-acdb-reactor (vla-get-count (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))))
												   '(
												   		(:vlr-objectappended . object_appended)
												     	(:vlr-objectunappended . object_appended)
												    )
								  )
	)
)

;***********************************************************************************************************************************

(defun object_appended (reactor_object parameter_list)
	(setq last_number_is (vla-get-count (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))))
		  last_number_was (vlr-data reactor_object)
		  selected_objects (vl-sort (append selected_objects (list (- last_number_is last_number_was))) '<)
	)
)

;***********************************************************************************************************************************

(defun command_will_start (reactor_object parameter_list)
	(vlr-data-set object_appended_reactor (vla-get-count (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))))
)

;***********************************************************************************************************************************

(defun command_ended (reactor_object parameter_list)
	(vlr-data-set object_appended_reactor (vla-get-count (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))))
	(cond
		(
			(and selected_objects
				(zerop (car selected_objects))
			)
				(setq was_selected (apply '- (reverse selected_objects)))
				(if (/= 2 (length selected_objects))
					  (setq last_number_is (1- last_number_is))
				)
		)
		(
			t
				(setq was_selected (car selected_objects))
		)
	)
	(setq selected_objects nil)
)

;***********************************************************************************************************************************

(if (/= 'vlr-command-reactor  (type command_will_start_reactor))
	(setq command_will_start_reactor (vlr-command-reactor nil '((:vlr-commandwillstart . command_will_start))))
)

;***********************************************************************************************************************************

(if (/= 'vlr-command-reactor  (type command_ended_reactor))
	(setq command_ended_reactor (vlr-command-reactor nil '(
														   (:vlr-commandended . command_ended)
														   (:vlr-commandcancelled . command_ended)
														   (:vlr-commandfailed . command_ended)
														  )
								)
	)
)

;***********************************************************************************************************************************

(defun select_last_added (/ sset last_number)
	(if (and (> last_number_is last_number_was)
			 was_selected
			 (not (minusp was_selected))
		)
		(progn
			(setq sset (ssadd)
				  last_number (1- last_number_is)
			)
			(repeat was_selected
				(ssadd (vlax-vla-object->ename (vla-item (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) last_number)) sset)
				(setq last_number (1- last_number))
			)
			(sssetfirst nil sset)
		)
		(princ "Selection data unavailable")
	)
	(princ)
)

;***********************************************************************************************************************************

 

Message 4 of 8

Ahmed_204
Enthusiast
Enthusiast

Hi @komondormrex

first of all , thank you for your support.

May I ask how to call this function in AutoCAD ?

 

Thanks for your Support 

Ahmed Hisham 

0 Likes
Message 5 of 8

Ahmed_204
Enthusiast
Enthusiast

Hi @calderg1000 ,

 

I tried to do so but its still not working with the dynamic Blocks.

 

0 Likes
Message 6 of 8

komondormrex
Mentor
Mentor

hi, 

you may call the function by entering (select_last_added) <enter>in command line. 

0 Likes
Message 7 of 8

calderg1000
Mentor
Mentor

Regards @Ahmed_204 

Here I give you a demonstration of how it works.

 

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Message 8 of 8

Ahmed_204
Enthusiast
Enthusiast

Hi @calderg1000 ,

 

I really appreciate your support and you are right the routine is working fine with dynamic blocks but not working with blocks that are having attributes inside and will give you this message in the command line " ; error: bad argument type: lselsetp nil" 

 

I will attach a drawing containing a dynamic block having attribute that you can try so , we can update the lisp to work with such situation.

 

Thank you for your help

Ahmed Hisham

0 Likes