Jump to content

Creating a dimension using autolisp


samifox

Recommended Posts

Hi

 

i want to draw a polyline , and as i hit enter or "C" i want autolisp to create dimention for every polyline segment.

 

this code acting weird on me, it seems like the interpreter skips the "_pline" command

 

need some help

 

(defun C:Test (/ pts p1 p2)

 (command "_pline");_create pline

  ;_get its verts list
 (setq	pts (mapcar 'cdr
	    (vl-remove-if-not
	      '(lambda (e) (= (Car e) 10))
	      (entget (entlast))
	    )
    )
 )
 ;_execute the dim command with every pair of verts,
 ;_ divide thier distance by to to get middle way location
 (setq i 0)
 (while (> i (length pts))
   (setq p1 (nth i pts))
   (setq p2 ((nth (+ i 1)pts)))
   (command "DIMLINEAR" "" p1 p2 (/ (distance p1 p2) 2 ))
   (setq i (+ i 2))
   )  
)

Link to comment
Share on other sites

(command "_.pline")
(while (= 1 (logand 1 (getvar 'cmdactive))) (command "\\"))

...

 

LEE please explain what logand and logor actually doing (cant understand the one line exp in the help)

Link to comment
Share on other sites

For lets says the visibility flag for a 3DFACE

 

(setq flag (cdr (assoc 70 ed)))

(if (/= (logand flag 1) 1)
   (setq flag (+ flag 1)))

(logior flag 1)

 

These are equivalent functions that forces bit 1 to be set in a bit flag. Or the first edge to be hidden.

 

( logand ) tests to see if the bits is set, ( logior ) forces the bit to be set

 

(setq flag 2)
;; 0 0 1 0

(= (logand flag 1) 1)  ; returns nil - the 1 bit is not set
(= (logand flag 2) 2)  ; returns t
(= (logans flag 4) 4)  ; returns nil - the 4 bit is not set
(= (logand flag  8)  ; returns nil - the 8 bit is not set

 

 

HTH -David

Link to comment
Share on other sites

all i understand is , 0 as false and 1 as true ,

(if (= (logand 1 1) 1)

 

if i got it correctly , how i can know for example if 48 is true or false?

 

Thanks

Shay

Link to comment
Share on other sites

yes , i spent about 3 hours..but im not smart like you LEE;)

 

i knew nothing about binary system before i read the provided links ,

i understand that when we write (logand 1 1) we will get 1 , becuse AND will return 1 only if all arguments are 1, etc

 

do i got it right till this point?

Link to comment
Share on other sites

Here is a very old explanation of bitwises test from Dietmar Rudolph from the CompServe days ;

 

The number 53 is investigated :

 


;|Don,

logior and logand assume that the integer you pass as an argument is in fact 
a list of bits. Here's a routine from my book on LISP programming, which 
prints an integer as a list of bits:
|;

(defun print-bits (Bits / Bit-list Max-bit)
 (if (minusp Bits)
   (setq Max-bit 1
         Bits (- Bits 2147483648))
   (setq Max-bit 0)
 )
 (repeat 31
   (setq Bit-list (cons (rem Bits 2) Bit-list)
         Bits (/ Bits 2))
 )
 (cons Max-bit Bit-list)
)

;Here are some examples of the functions working on bit-coded integers:


Command: (print-bits 53)
(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 1)

Command: (print-bits (~ 53))            ; Bit-wise complement
(1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 0 1 0)

Command: (print-bits (lsh 53 4))        ; left shift by four bits
(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 1 0 0 0 0)

Command: (print-bits 24)
(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0)

Command: (print-bits (logand 53 24))    ; bit-wise and
(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0)

Command: (print-bits (logior 53 24))    ; bit-wise or
(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 1)

Command: (print-bits (boole 6 53 24))   ; bit-wise xor
(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 1)

;Dietmar

 

 

HTH -David

Link to comment
Share on other sites

Ok,

i think i got it ,

 

AND general logic is :

 

true + true = true

true + false = false

false + true = false

false + false = false

 

now, if true is 1 and false is 0

 

Command : (logand 1 0)

Command : 0

 

meaning true + false = false , etc

 

now when dealing with integers, we dealing actually with groups of 32 bits

 

so what is going in the backstage of this :

 

Command : (logand 27 43)

Command : 11

 

27 represents in binary as : 00011011

43 represents in binary as : 00101011

 

1+1= 1

1+1= 1

0+0= 0

1+1= 1

1+0= 0

0+1= 0

0+0= 0

0+0= 0

 

00001011 represents in decimal as 11

 

ok, so going back to my actual subject, i had a problem becuase i call the "pline" command , and than i call the "linear" command , for some reason (that i dont understand" i have to wait until "pline" will complete and than i can call the next command

 

so in MAC LEE code:

 

(command "_.pline")
(while (= 1 (logand 1 (getvar 'cmdactive'))) (command "\\"))

 

excute "pline"

while --> previous command is active

excute command

 

i was thinking the inner command will be excuted while there is no active command

 

im confused

Link to comment
Share on other sites

ok,

 

this is the code i wish to execute

 

-- > i call the command "_pline"

-- > (user pick points on-screen and finish by pressing "C" or "Enter"

-- > verts of the last entity are being listed

-- > a dimension entity is generated by every pair of verts

 

this is the code i got so far:

 

(defun C:Test (/ pts p1 p2)

 (command "_pline") ;_create pline

 (while (= 1 (logand 1 (getvar "cmdactive")))
   (setq pts
   (mapcar 'cdr
	   (vl-remove-if-not
	     '(lambda (e) (= (Car e) 10))
	     (entget (entlast))
	   )
   )
   )
;_execute the dim command with every pair of verts,
;_ divide thier distance by 2 to get middle way location
   (setq i 0)
   (while (> i (length pts))
     (setq p1 (nth i pts))
     (setq p2 ((nth (+ i 1) pts)))
     (command "DIMLINEAR" "" p1 p2 (/ (distance p1 p2) 2))
     (setq i (+ i 2))
   )
 )
)

Link to comment
Share on other sites

(command "_.pline")
(while (= 1 (logand 1 (getvar 'cmdactive))) (command "\\"))

...

 

Hi LEE

 

if you look into my self monolog posts :D , i did understand the (logend) function thanks to the provided links

 

so thank you

 

i've manage to write this working script

 

defun C:Test (/ pts p1 p2)
 (command "_pline") ;_create pline
 (while (= (getvar "cmdactive") 1)
   (command pause)
 )					
 (mapcar 'cdr
	 (vl-remove-if-not
	   (function (lambda (e) (= (Car e) 10)))
	   (entget (entlast))
	 )
 )
 )
 (setq i 0)
 (while (< i (- (length pts) 1))
   (setq p1 (nth i pts))
   (setq p2 (nth (+ i 1) pts))
   (command "DIMLINEAR" p1 p2 p2)
   (setq i (+ i 1))
 )
)

 

now, i need help on creating a dim style and accocoate it with the above script dim lines. how to create a new dim style?

 

THanks

Shay

Link to comment
Share on other sites

  • 11 months later...

Helllo sir,

Right now I am stuck at one place in my coding work. I have to extract some dimension from the given drawing by just a single click on object. I have done some coding using autolisp with help of DXF codes, but it is somewhat interactive, and my requirement is to make them fully automatic output by just one click. So , sir in this case I will require your kind help.

 

I am sharing two drawing files (Isometric and 2D) with you, so that you can get idea about the object.

 

sw isometric image :https://drive.google.com/file/d/0BxdLhJh0DwGRbFY3TlNGRVdIalU/view?usp=sharing

 

2D image: https://drive.google.com/file/d/0BxdLhJh0DwGROEhJVmZDRWY1RjQ/view?usp=sharing

 

Drawing:

https://drive.google.com/file/d/0BxdLhJh0DwGRdzdJYkFVMGItX0E/view?usp=sharing

 

Output should be as :

 

a=____

b=____

c=____

d=____

 

Sir, please help me in this regard.

 

Thanking you,

Soham

mail id : sohamteraiya@gmail.com

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