Jump to content

Recommended Posts

Posted

I've just started playing with autolisp and here's a problem that I'm having. I want the lisp to draw a construction line base on a point, trim numberous lines to it and then erase it. The onjly problem that I'm having is that it trims the wrong side of the line...can someone please help the code is below.

 

(defun c:trp (/ pt ui xl ob sel fil)

(setq pt (getpoint))

(initget "VERtical HORizontal _VER HOR")

(command "_xline" (setq ui (getkword "\nWhich direction? (VERtical/HORizontal)")) pt "")

(setq xl (entlast))

(setq sel (ssget w))

(command "_trim" xl "" \ "")

(command "_erase" xl "")(princ))

Posted
I've just started playing with autolisp and here's a problem that I'm having. I want the lisp to draw a construction line base on a point, trim numberous lines to it and then erase it. The onjly problem that I'm having is that it trims the wrong side of the line...can someone please help the code is below.

 

(defun c:trp (/ pt ui xl ob sel fil)

(setq pt (getpoint))

(initget "VERtical HORizontal _VER HOR")

(command "_xline" (setq ui (getkword "\nWhich direction? (VERtical/HORizontal)")) pt "")

(setq xl (entlast))

(setq sel (ssget w))

(command "_trim" xl "" \ "")

(command "_erase" xl "")(princ))

 

 

Try this:

 

(defun c:trp (/ pt ui xl)
 (setq pt (getpoint "\nPick Point: "))
 (initget "V H")
 (command "._xline"
      (setq ui (getkword "\nWhich direction? (Vertical/Horizontal)"))
      pt
      ""
 )
 (setq xl (entlast))  
 (command "._trim" xl "")  
 (while
   (eq 1 (logand (getvar "CMDACTIVE") 1))
   (command PAUSE)
 )
 (entdel xl)
 (princ)
)

Posted

Thanks alot....it works great. I was hoping that sometime if you have the time you could explain what it means...ie how you did it. Like I said I've just started with AutoLISP and I still have a whole lot to learn and you can't really ask books "how do you do that?".

Thanks again for the response!

Mike

Posted

(defun c:trp (/ pt ui xl)

(setq pt (getpoint "\nPick Point: "))

(initget "V H")

(command "._xline"

(setq ui (getkword "\nWhich direction? (Vertical/Horizontal)"))

pt

""

)

(setq xl (entlast))

(command "._trim" xl "")

(while

(eq 1 (logand (getvar "CMDACTIVE") 1))

(command PAUSE)

)

(entdel xl)

(princ)

)

 

 

Another method would be to calculate the trim points and alter the endpoints of the lines that are "trimmed". This way you don't have to call (command "._trim"....)

Posted

Thanks a lot RKM. All of that stuff makes sense to me except for this part:

 

(eq 1 (logand (getvar "CMDACTIVE") 1))

(command PAUSE)

 

I guess I just don't understand how the "eq 1", "logand" and CMDACTIVE actions work.

 

Thanks for everything though!

Mike

Posted

(logand) function

 

Integer bit flag comparison

Bit values

0000 = 0
0001 = 1
0010 = 2
0011 = 3
0100 = 4
0101 = 5
0110 = 6
0111 = 7
1000 = 8
1001 = 9
1010 = 10
1011 = 11
1100 = 12
1101 = 13
1110 = 14
1111 = 15

 

 

(logand flag bit)

 

;;;check to see if the bit is set in the flag value

;;;Returns the bit number if T

;;;Returns 0 if nil

 

(logand 5 1)

;;;Returns 1 - the 1 bit is set - 5 = 0101 or 4+1

 

(logand 5 2)

;;;retruns 0 - the 2 bit is not set

 

So the test would be

(if (= (logand 5 1) 1)

(then do this)

(else do that))

 

Or

(while (eq 1 (logand (getvar "CMDACTIVE") 1))

(command pause))

 

Which says that while the command is active, pause for user input.

 

 

I usually use

 

(while (> (getvar "CMDACTIVE") 0)

(command pause))

 

 

 

HTH -David

Posted

Perfect...now I actually understand what all that means! haha thanks a lot!

Posted

Bitflags are fairly elementary computer science entities.

 

An easy way to see them work are with the visibility of edges with 3DFACEs. The flag is contained in the DXF group 70 value. If the first edge is invisible, then the flag 1 bit is set. The 2nd edge sets the 2 bit, 3 edge the 4 bit, 4th edge the 8 bit.

 

So if group 70 = 15, all of the edges are invisible. -David

Posted
Thanks a lot RKM. All of that stuff makes sense to me except for this part:

 

(eq 1 (logand (getvar "CMDACTIVE") 1))

(command PAUSE)

 

I guess I just don't understand how the "eq 1", "logand" and CMDACTIVE actions work.

 

Thanks for everything though!

Mike

 

Here is the best explanation I know of...

http://tinyurl.com/dnpl5

  • 3 years later...
Posted

a useful thread. It definitely explained quite a bit, however I also brings up more questions...at least for me.

 

I read the post and my question is what "right or left most bit" mean?

 

Here, each digit represents a distinct logical true/false

state (five significant ones in this number), as shown in

this table:

 

Bit 1: FALSE (right-most bit)

Bit 2: TRUE

Bit 3: TRUE

Bit 4: FALSE

Bit 5: TRUE (left-most bit)

Posted

I believe the red is right-most:

 

10110110101[b][color=Red]1[/color][/b]

  • 1 year later...

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