Jump to content

Recommended Posts

Posted

im trying to make a lisp that draws a ruller.

frame spacing, starting frame number, ending frame number and scale to be input.

unfortunately, im new at lisp and it doesnt work. can anyone help pls?

framing.LSP

framing.dwg

Posted

Here's a quick one:

 

(defun c:foo (/ a d i n p p2)
 ;; RJP - 04-10-2018
 ;; Creates a simple ruler
 (cond	((and (not (initget 7))
      (setq i (getint "\nEnter spacing: "))
      (setq p (getpoint "\nPick start point: "))
      (setq d (getdist p "\nPick Distance: "))
 )
 (setq n 0)
 (while	(<= n d)
   (entmakex (list '(0 . "LINE")
		   (cons 10 (setq p2 (polar p 0. n)))
		   (cons 11
			 (list (car p2)
			       (- (cadr p2)
				  (cond	((setq a (= 0 (rem n 5))) 2.)
					(1.)
				  )
			       )
			 )
		   )
		   (cons 62
			 (if a
			   1
			   2
			 )
		   )
	     )
   )
   (if a
     (entmakex (list '(0 . "TEXT")
		     '(100 . "AcDbEntity")
		     '(67 . 0)
		     '(8 . "0")
		     '(62 . 4)
		     '(100 . "AcDbText")
		     (cons 10 (list (car p2) (- (cadr p2) 3.)))
		     '(40 . 2.0)
		     (cons 1 (itoa (fix (/ (distance p p2) i))))
		     '(41 . 1.0)
		     '(7 . "Standard")
		     '(71 . 0)
		     '(72 . 1)
		     (cons 11 (list (car p2) (- (cadr p2) 3.)))
		     '(100 . "AcDbText")
		     '(73 . 3)
	       )
     )
   )
   (setq n (+ n i))
 )
)
 )
 (princ)
)

Posted

thnx for quick reply. this is really good.

but i want to add "scale factor" that changes text heights and line lengths. ie if spacing is 500mm, texts and lines are too short.

also stating frame number and ending frame number is important.

by the way, what is wrong with my lisp?

Posted

by the way, what is wrong with my lisp?

 

The subfunction 'MakeBlockA' you use has alot of issues, like faulty cond, faulty list constructions, entmaking "ENDBLK" within the repeat loop, are you sure it has to repeat for b or it should be (abs (- b a)).

I'd use unique name for the block definition such as (strcat "framing_" a "_" b "_" fs "_" sc) to account the possible multiple versions

And would also localise all the variables and pass them locally to that subfunction.

Posted

i've work on it but i have still some problems. i cant change text height by scale factor. this is last version;

 

(defun c:framing ()

(setq a (getint "\nstart frame :"))

(setq b (getint "\nend frame :"))

(setq fs (getint "\nframe spacing :"))

(setq sc (getint "\nscale :"))

(setq sca (* 2 sc))

(if (not (tblsearch "BLOCK" "rullerA")) (MakeBlockA))

(if (not (ssget "X" (list '(0 . "INSERT") '(2 . "rullerA")))) (entmake (list '(0 . "INSERT") '(2 . "rullerA") '(10 0 0 0))))

 

(princ)

)

(defun MakeBlockA()

(entmake (list '(0 . "BLOCK") '(2 . "rullerA") '(10 0.0 0.0 0.0)'(70 . 0)))

(setq i a)

(repeat ( + b 1)

(setq ii (* i fs))

(cond

((= (* 5 (/ i 5)) i) (progn

(setq m 2)

(setq n 1)

(setq scb (* -5 sc))

(entmake (list '(0 . "text") (list 10 ii scb 0) (list 11 ii scb 0) (cons 1 (itoa i)) '(40 . 75) (cons 50 0.0) (cons 71 0) (cons 72 1) (cons 73 0) (cons 62 4) ))

)

)

)

(setq scc (* -1 sc))

(entmake (list '(0 . "LINE") (list 10 ii 0 0) (list 11 ii (* scc m) 0) (cons 62 n)))

(setq i (1+ i) m 1)

(setq n 2)

)

 

(entmake (list '(0 . "ENDBLK")))

)

Posted

Not a lot of time to look at this, but give this a try:

Also use code tags for legibility.

(defun c:framing (/ a b fs i ii m n sc sca scb scc) ;;<<-- Localize variables!
 (if (and (setq a (getint "\nstart frame :"))
   (setq b (getint "\nend frame :"))
   (setq fs (getint "\nframe spacing :"))
   (setq sc (getint "\nscale :"))
   (setq sca (* 2 sc))
   (not (ssget "X" (list '(0 . "INSERT") '(2 . "rullerA"))))
     )
   (progn
     (if (not (tblsearch "BLOCK" "rullerA"))
(progn (entmake (list '(0 . "BLOCK") '(2 . "rullerA") '(10 0.0 0.0 0.0) '(70 . 0)))
       (setq i a)
       (repeat (+ b 1)
	 (setq ii (* i fs))
	 (cond ((= (* 5 (/ i 5)) i)
		(progn (setq m 2)
		       (setq n 1)
		       (setq scb (* -5 sc))
		       (entmake	(list '(0 . "text")
				      (list 10 ii scb 0)
				      (list 11 ii scb 0)
				      (cons 1 (itoa i))
				      (cons 40 (* 2. sc))
				      (cons 50 0.0)
				      (cons 71 0)
				      (cons 72 1)
				      (cons 73 0)
				      (cons 62 4)
				)
		       )
		)
	       )
	 )
	 (setq scc (* -1 sc))
	 (entmake (list '(0 . "LINE") (list 10 ii 0 0) (list 11 ii (* scc m) 0) (cons 62 n)))
	 (setq i (1+ i)
	       m 1
	 )
	 (setq n 2)
       )
       (entmake (list '(0 . "ENDBLK")))
)
     )
     (entmake (list '(0 . "INSERT") '(2 . "rullerA") '(10 0 0 0)))
   )
 )
 (princ)
)

Posted

hi ronjonp,

thnx for help and code tag thing :) it works good for me.

now, there is another problem that grrr suggested solution but i cant do; naming the block.

i tried to use (strcat "framing_" a "_" b "_" fs "_" sc) but it gives error:

bad DXF group: (2 STRCAT "framing_" A "_" B "_" FS "_" SC)

Posted

You're trying to pass numbers to a function that only accepts strings.

 

(defun c:framing (/ a b bn fs i ii m n sc scb scc);;<<-- Localize variables!
 (if (and (setq a (getint "\nstart frame :"))
   (setq b (getint "\nend frame :"))
   (setq fs (getint "\nframe spacing :"))
   (setq sc (getint "\nscale :"))
     )
   (progn
     (if
(not
  (tblsearch "BLOCK"
	     (setq bn (strcat "framing_" (itoa a) "_" (itoa b) "_" (itoa fs) "_" (itoa sc)))
  )
)
 (progn	(entmake (list '(0 . "BLOCK") (cons 2 bn) '(10 0.0 0.0 0.0) '(70 . 0)))
	(setq i a)
	(repeat	(+ b 1)
	  (setq ii (* i fs))
	  (cond	((= (* 5 (/ i 5)) i)
		 (progn	(setq m 2)
			(setq n 1)
			(setq scb (* -5 sc))
			(entmake (list '(0 . "text")
				       (list 10 ii scb 0)
				       (list 11 ii scb 0)
				       (cons 1 (itoa i))
				       (cons 40 (* 2. sc))
				       (cons 50 0.0)
				       (cons 71 0)
				       (cons 72 1)
				       (cons 73 0)
				       (cons 62 4)
				 )
			)
		 )
		)
	  )
	  (setq scc (* -1 sc))
	  (entmake (list '(0 . "LINE") (list 10 ii 0 0) (list 11 ii (* scc m) 0) (cons 62 n)))
	  (setq	i (1+ i)
		m 1
	  )
	  (setq n 2)
	)
	(entmake (list '(0 . "ENDBLK")))
	(entmake (list '(0 . "INSERT") (cons 2 bn) '(10 0 0 0)))
 )
 (alert "Block already exists!!")
     )
   )
 )
 (princ)
)

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