Jump to content

Lisp to select and hatch objects


pixel8er

Recommended Posts

  • Replies 26
  • Created
  • Last Reply

Top Posters In This Topic

  • Tharwat

    10

  • pixel8er

    8

  • Lee Mac

    6

  • BIGAL

    1

Top Posters In This Topic

Posted Images

Another hint: from the Visual LISP IDE Help Documentation, section:

 

>> AutoLISP Developer's Guide

>> Using the AutoLISP Language
>> Using AutoLISP to Manipulate AutoCAD Objects
>> Selection Set Handling
>> Selection Set Filter Lists
>> Relational Tests

The bitwise operators "&" and "&=" are valid only for integer-valued groups.

 

The bitwise AND, "&", is true if ((integer_group & filter) /= 0) - that is, if any of the bits set in the mask are also set in the integer group.

 

The bitwise masked equals, "&=", is true if ((integer_group & filter) = filter) - that is, if all bits set in the mask are also set in the integer_group (other bits might be set in the integer_group but are not checked).

 

Read the ((integer_group & filter) /= 0) examples as:

 

"&"   ==>  (/= 0 (logand bit filter))

"&="  ==>  (= filter (logand bit filter))

Note that, for this task, since we are only testing for a single bit (1 = closed), either the Bitwise AND "&" or the Bitwise masked equals "&=" will work, but I would use the Bitwise masked equals for clarity of intention.

Link to comment
Share on other sites

Am I wasting my time with this?

 

Certainly , you know you are not , and me as well as the others always appreciate your hard work and unique solutions and explanations with the nice words that standing behind them .

 

I apologize for the late replay to this :oops:

 

So I can say that the "&=" would consider all bitwises that are belong to group 70 for LWpolyline and Polyline , and the "&="

would wrap all bitwises for 70 which means the following .

 

1 = This is a closed polyline (or a polygon mesh closed in the M direction)

2 = Curve-fit vertices have been added

4 = Spline-fit vertices have been added

8 = This is a 3D polyline

16 = This is a 3D polygon mesh

32 = The polygon mesh is closed in the N direction

64 = The polyline is a polyface mesh

128 = The linetype pattern is generated continuously around the vertices of this polyline

 

And in our case the rest of the bitwises for group 70 won't affect negatively at the selection set of the closed *Polylines .

 

Another alternative codes for the (-4 . "&=")

 

(ssget "_x"
      '(
        (-4 . "<or")
        (0 . "*POLYLINE")
        (70 . 1)
        (70 . 128)
        (-4 . "or>")
       )
)

 

Hope that I was clear enough .:)

 

Best regards.

 

Tharwat

Link to comment
Share on other sites

I apologize for the late replay to this :oops:

 

Not a problem, I was undecided as to whether to offer any more 'hints' without interest was all.

 

Another alternative codes for the (-4 . "&=")

 

(ssget "_x"
      '(
        (-4 . "<or")
        (0 . "*POLYLINE")
        (70 . 1)
        (70 . 128)
        (-4 . "or>")
       )
)

 

Not quite: your filter would allow the user to select either:

 

  • LWPoyline/Polylines with ANY DXF 70 code,
  • Those with DXF 70 = 1
  • Or, Those with DXF 70 = 128

We wish to restrict the selection to only Closed LWPolylines/Polylines, but still allowing LWPolylines/Polylines which are Closed and with Linetype Generation ON, or perhaps for the Polyline, Closed with Curve-fit Vertices etc.

 

Let's focus on LWPolylines first:

 

Say I have an LWPolyline with the following data:

 

(
 (0 . "LWPOLYLINE")
 (100 . "AcDbEntity")
 (100 . "AcDbPolyline")
 (90 . 4)
 (70 . 129)
 (10 0.0 0.0)
 (10 1.0 0.0)
 (10 1.0 1.0)
 (10 0.0 1.0)
)

Notice that the above LWPolyline is closed (= 1 (logand 1 129)) and has Linetype Generation ON (= 128 (logand 128 129))

 

The Binary representation of this bit code would look like this:

 

       128 64 32 16  8  4  2  1
----------------------------------------
         1  0  0  0  0  0  0  1  =  129

So using the "&=" filter we can mask specific bits and test for those we need:

 

(ssget '((0 . "LWPOLYLINE") (-4 . "&=") (70 . 1)))

This has the behaviour of:

 

(= 1 (logand 1 <DXF 70>))

In the binary representation:

 

       128 64 32 16  8  4  2  1
----------------------------------------
         1  0  0  0  0  0  0  1  =  129
         0  0  0  0  0  0  0  1  =    1
----------------------------------------
LOGAND:   0  0  0  0  0  0  0  1  =    1

For POLYLINE entities, the filter needs to be a little more strict, since you would also want to exclude Closed Polyline Mesh entities, but at risk of information overload, I'll leave that for another day. :)

Link to comment
Share on other sites

Tharwat,

 

I think you'll benefit from a better understanding of such functions as logand / logior etc.

 

I would suggest you have a read of this explanation and I've also tried to put a small explanation together here which may help.

 

Lee

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