Jump to content

bad function: -4.0


ahyin

Recommended Posts

Dear All,

 

Please help for correct my code, I want to select all polylines in layer1 and layer2 but got error message of bad function: -4.0, anything wrong with my code ?

 

Thanks !

 

(setq total (ssget "x" (list '(0 . "lwpolyline") (-4. "<and") (cons 8 "layer1")(cons 8 "layer2") <-4. "and>")(cons 410 (getvar "ctab")))))

Link to comment
Share on other sites

Your ")

 

is wrong.Correct is

(-4 . "and>") And i think you must use OR instead of AND ^^ One object can't be on two layer.

Edited by ketxu
Link to comment
Share on other sites

There are two ways you can approach this, using the Logical Filter codes:

 

(ssget "_X"
 (list
  '(0 . "LWPOLYLINE")
  '(-4 . "<OR")
  '(8 . "layer1")
  '(8 . "layer2")
  '(-4 . "OR>")
   (cons 410 (getvar "ctab"))
 )
)

Or using a Wildcard filter, such as:

 

(ssget "_X"
 (list
  '(0 . "LWPOLYLINE")
  '(8 . "layer[12]")
   (cons 410 (getvar "ctab"))
 )
)

I would recommend you read all sections of the Visual LISP IDE Help Documentation under:

 

AutoLISP Developers Guide > Using the AutoLISP Language > Using AutoLISP to Manipulate AutoCAD Objects > Selection Set Handling

 

Also, have a read of this regarding use of the apostrophe to mark expressions as literal.

Link to comment
Share on other sites

Dear Lee Mac,

 

If I use the function vlax-get-property to get the layer name and make the selection set the below code correct or not ?

 

](ssget "_X"
 (list
  '(0 . "LWPOLYLINE") 
  '(-4 . "<OR")
  '(8 . (vlax-get-property object1 'Name))
  '(8 . (vlax-get-property object2 'Name))  
  '(-4 . "OR>")
   (cons 410 (getvar "ctab"))
 )
)

 

 

There are two ways you can approach this, using the Logical Filter codes:

 

(ssget "_X"
 (list
  '(0 . "LWPOLYLINE")
  '(-4 . "<OR")
  '(8 . "layer1")
  '(8 . "layer2")
  '(-4 . "OR>")
   (cons 410 (getvar "ctab"))
 )
)

Or using a Wildcard filter, such as:

 

(ssget "_X"
 (list
  '(0 . "LWPOLYLINE")
  '(8 . "layer[12]")
   (cons 410 (getvar "ctab"))
 )
)

I would recommend you read all sections of the Visual LISP IDE Help Documentation under:

 

AutoLISP Developers Guide > Using the AutoLISP Language > Using AutoLISP to Manipulate AutoCAD Objects > Selection Set Handling

 

Also, have a read of this regarding use of the apostrophe to mark expressions as literal.

Link to comment
Share on other sites

If I use the function vlax-get-property to get the layer name and make the selection set the below code correct or not ?

 

IMO - Someone didn't listen to good advice :):

 

I would recommend you read all sections of the Visual LISP IDE Help Documentation under:

 

AutoLISP Developers Guide > Using the AutoLISP Language > Using AutoLISP to Manipulate AutoCAD Objects > Selection Set Handling

 

Also, have a read of this regarding use of the apostrophe to mark expressions as literal.

 

... In any event, use cons when evaluating an expression:

 

(ssget "_X"
 (list
  '(0 . "LWPOLYLINE") 
  '(-4 . "<OR")
  [color="red"]([/color][color="blue"]cons [/color]8 (vlax-get-property object1 'Layer)[color="red"])[/color]
  [color="red"]([/color][color="blue"]cons[/color] 8 (vlax-get-property object2 'Layer)[color="red"])[/color]  
  '(-4 . "OR>")
  (cons 410 (getvar "ctab"))
 )
)

 

HTH

Edited by BlackBox
Link to comment
Share on other sites

Could a LWpolyline have a property of name or a layer name ?:unsure:

 

And how to filter for Layer name ( vlax-get-property.....before with the variable holds the selection set of objects to get the layer name of them ?

 

Am I right or misunderstood the idea ?

 

Thanks

Link to comment
Share on other sites

Could a LWpolyline have a property of name or a layer name ?:unsure:

 

I *believe* an Entity Object has a "Layer" property, whereas a Layer Object has a "Name" property.

 

And how to filter for Layer name ( vlax-get-property.....before with the variable holds the selection set of objects to get the layer name of them ?

 

Am I right or misunderstood the idea ?

 

Honestly, I too would need more information to answer this with regard to the OP's intention.

 

However, here's one way to feed an ssget filter object information:

 

(vl-load-com)
(if (and (setq e (car (entsel "\nPick any object on the desired layer: ")))
        (setq v (vlax-ename->vla-object e)))
 (progn
   (ssget "_X"
       (list
         '(0 . "LWPOLYLINE") 
         (cons 8 (vlax-get-property v 'Layer))
         (cons 410 (getvar "ctab"))))
   ;; ... More code
   )
 )

Link to comment
Share on other sites

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...