Jump to content

Recommended Posts

Posted

I'm a newbie. And i try to practise some Autolisp example.

I write the code below to know how to use entity name in applying command.

I collect these entity name in a list and use command "erase to delete it".

But some problems happened here. It said " Bad arguments" and i don't know how to resolve it.

 

(defun c:gc (/ p1 p2 data n index)

(setq p1 (ssget))

(setq data())

(setq n (sslength p1))

(setq index 0)

(repeat n

(setq p2 (ssname p1 index))

(setq data (append data p2))

(entmod data)

(setq index (+ index 1))

)

(command "erase" p2 "")

)

Posted

I'm confused....can you paste the exact error it's giving you?

It looks like everything there is fine except i'm not understand what you're trying to do with the

Data

variable ?

Posted (edited)

The ssget is fine, you're assigning to variable p1....then assigning "n" to the length of sset p1...then you set up a counter, that supplies the (ssname) function with it's index argument....

so you've got your ssget with no filter, so this basically is like (ENTSEL) because you're just getting one object in a selection set manually.

You would use filters with ssget in order to select items automatically....

So entsel=1 item, ssget=multiple items.

After you're getting the entity name by doing (setq p2 (ssname p1 index)), you can assign that to a variable and supply the erase command with the var...not sure what the data is doing I see (entmod) on a variable that's an empty list?

I don't think it works like that and I think that's the cause of your error.

Edited by Bhull1985
Posted

There is no need to iterate through each entity name to delete since the command erase could erase a selection set .

 

(if (setq s (ssget "_:L" ))
(command "_.erase" s "")
)

Posted
I'm a newbie. And i try to practise some Autolisp example.

I write the code below to know how to use entity name in applying command.

 

yeah tharwat definitely he can supply erase with a selection set and bypass but I think he was just trying to exercise...that's why I was trying to explain what I saw.....do you see a good use for data variable how he is doing it?

Posted
yeah tharwat definitely he can supply erase with a selection set and bypass but I think he was just trying to exercise...that's why I was trying to explain what I saw

I had nothing to add to what you have nicely described earlier and that's why I post only simple example codes ;)

 

 

do you see a good use for data variable how he is doing it?

 

I think it is nothing more than copy and paste codes or a modification on codes that related to another aim than the one they driven their codes to and

that's why things took the wrong place though I could be wrong :)

Posted

Ahh I see, alrighty then. Was thinking it was something maybe that I didn't know about yet.

Posted

(defun c:gc (/ p1 p2 data n index)
(setq p1 (ssget))
(setq data())[color="green"] ;; you don't need this[/color]
(setq n (sslength p1))
(setq index 0)
(repeat n
(setq p2 (ssname p1 index))
(setq data (append data p2))[color="green"] ; append is used with list, "data" variable is not a list
                            ;  this is where your error occurred              [/color]
(entmod data) [color="green"]; you don't need this[/color]
(setq index (+ index 1))
) [color="green"]; repeat function ends without processing an entity[/color]
(command "erase" p2 "")[color="green"] ;must be inside of the repeat function 
                       ;put this before you increment the index counter[/color] 
)

 

after

 

(defun c:gc (/ p1 p2 n index)
(setq p1 (ssget))
(setq n (sslength p1))
(setq index 0)
(repeat n
(setq p2 (ssname p1 index))
(command "erase" p2 "") 
(setq index (+ index 1))
)
(princ) ;exist cleanly
)

Posted

Thank for your help bhull1985, tharwat, jdiala.

I known my problem happen in (setq data (append data p2)).

And i tried another code to fix this.

I used ssadd to add the

An exact thing i want is used "select" command to select object object with an exact order.

Example : one line and one text (l1 t1) ; (l2 t2).( l3 t3)...

But when i run this code, i don't have the result i want.

I select a line and it choose the other lines ( or text), not a text attach with it.

(defun c:gc (/ p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 ss index n data start)

(setq p1 (ssget))

(setq n (sslength p1))

(setq index 0)

(setq data(ssadd))

(repeat n

(setq start (ssname p1 index))

(ssadd start data)

(setq p2 (entget start ))

(setq p3 (assoc 10 p2))

(setq p4 (assoc 11 p2))

(setq p5 (+ 100 (/ (+ (cadr p3) (cadr p4)) 2)))

(setq p6 (+ 100 (/ (+ (caddr p3) (caddr p4)) 2)))

(setq p7 (- 200 p5))

(setq p8 (- 200 p6))

(setq p9 (list p5 p6))

(setq p10 (list p7 p8 ))

(setq ss (ssget "C" p9 p10 '((0 . "text")) ))

(setq p11 (ssname ss 0))

(ssadd p11 data)

(setq index (+ index 1))

)

(command "select" data "")

(princ)

)

 

(defun c:gc (/ p1 p2 data n index)
(setq p1 (ssget))
(setq data())[color="green"] ;; you don't need this[/color]
(setq n (sslength p1))
(setq index 0)
(repeat n
(setq p2 (ssname p1 index))
(setq data (append data p2))[color="green"] ; append is used with list, "data" variable is not a list
                            ;  this is where your error occurred              [/color]
(entmod data) [color="green"]; you don't need this[/color]
(setq index (+ index 1))
) [color="green"]; repeat function ends without processing an entity[/color]
(command "erase" p2 "")[color="green"] ;must be inside of the repeat function 
                       ;put this before you increment the index counter[/color] 
)

 

after

 

(defun c:gc (/ p1 p2 n index)
(setq p1 (ssget))
(setq n (sslength p1))
(setq index 0)
(repeat n
(setq p2 (ssname p1 index))
(command "erase" p2 "") 
(setq index (+ index 1))
)
(princ) ;exist cleanly
)

 

There is no need to iterate through each entity name to delete since the command erase could erase a selection set .

 

(if (setq s (ssget "_:L" ))
(command "_.erase" s "")
)

 

The ssget is fine, you're assigning to variable p1....then assigning "n" to the length of sset p1...then you set up a counter, that supplies the (ssname) function with it's index argument....

so you've got your ssget with no filter, so this basically is like (ENTSEL) because you're just getting one object in a selection set manually.

You would use filters with ssget in order to select items automatically....

So entsel=1 item, ssget=multiple items.

After you're getting the entity name by doing (setq p2 (ssname p1 index)), you can assign that to a variable and supply the erase command with the var...not sure what the data is doing I see (entmod) on a variable?

I don't think it works like that and I think that's the cause of your error.

Posted

I have no clue what you are trying to accomplish, OP.

Posted

In this case, i have two object : 1 line attach with 1 object.. I want to select one line - one text for each couple. In this example, i assume the distance between the text and the line is 50. I've written this code, it don't have the result i want. It has an confusion between these couple. It's the first time i write a lisp

 

(defun c:gc (/ p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 ss index n data start)

(setq p1 (ssget '((0 . "line")))) ; select object : line

(setq n (sslength p1))

(setq index 0)

(setq data(ssadd))

(repeat n ; Create a loop

(setq start (ssname p1 index))

(ssadd start data) ;add entity name of 1st line

(setq p2 (entget start ))

(setq p3 (assoc 10 p2)) ; get start point

(setq p4 (assoc 11 p2)) ; get end point

(setq p5 (+ 100 (/ (+ (cadr p3) (cadr p4)) 2)))

(setq p6 (+ 100 (/ (+ (caddr p3) (caddr p4)) 2))) ;create a box selection with this point list

(setq p7 (- 200 p5))

(setq p8 (- 200 p6))

(setq p9 (list p5 p6))

(setq p10 (list p7 p8 ))

(setq ss (ssget "C" p9 p10 '((0 . "text")) )) ;Select object 2nd : text

(setq p11 (ssname ss 0))

(ssadd p11 data) ;add entity name of 2nd text to this list

(setq index (+ index 1))

)

(command "select" data "") ; select object in data list

(prin1 p5)

)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...