Jump to content

Defun - no fun!


firavolla

Recommended Posts

What am I doing wrong?? Arrghhhhhhh!:cry:

I have this function...inside the main lisp file of my routine. Whenever I reach the call to the function I get something like error bad function and then the the first element of L (something like error bad function 2.4)

The call to this function is just near the end of the main function, and it's like

(df)

 

The function is like:

 

(defun df ()
(setq wReazP2 (car L))

(setq p1 pStart)
(setq p0 (polar p1 (dtr 0.0) (wReazP2)))
(setq p2 (polar p1 (dtr 270.0) (hReaz)))
(setq p3 (polar p2 (dtr 0.0) (wReazP2)))

)

Link to comment
Share on other sites

Hi firavolla,

First, it's better to give a complete funtions in your Lisp file to identify the main problem, but so far that might be with (car L) and there is no need to remodify the start point as you did (setq p1 pStart) I mean use pStart instead of p1.

 

If you support all codes that would be much easier.

 

(defun df ()
(setq wReazP2 (car L))
(setq p1 pStart)
(setq p0 (polar p1 (dtr 0.0) (wReazP2)))
(setq p2 (polar p1 (dtr 270.0) (hReaz)))
(setq p3 (polar p2 (dtr 0.0) (wReazP2)))
)

 

Regards,

Tharwat

Link to comment
Share on other sites

What am I doing wrong?? Arrghhhhhhh!:cry:

I have this function...inside the main lisp file of my routine. Whenever I reach the call to the function I get something like error bad function and then the the first element of L (something like error bad function 2.4)

The call to this function is just near the end of the main function, and it's like

(df)

 

The function is like:

 

(defun df ()

(setq wReazP2 (car L))

 

(setq p1 pStart)

(setq p0 (polar p1 (dtr 0.0) (wReazP2)))

(setq p2 (polar p1 (dtr 270.0) (hReaz)))

(setq p3 (polar p2 (dtr 0.0) (wReazP2)))

 

)

firavolla,

 

It is difficult to give answers to questions like this when the rest of the code is not present. All you can do is just speculate. If the entire code was there, It could be tested to give someone a better idea as to what the problem is. Then you will get an exact answer much faster.

 

If you should decide to post the code, Then please use code tags. See this link on how to do that.:http://www.cadtutor.net/forum/showthread.php?t=9184

Link to comment
Share on other sites

(defun c:Grinda()

   (setq bBeam (getdist    "\n bBeam: "))
   (setq hBeam (getdist    "\n hBeam: "))
   

   (setq hSup   (* 3 hBeam))

   (setq nOp (getint "\n No.Op. "))
   (setq nSup (+ nOp 1))

   (setq L nil)
   (repeat nOp

       (setq L  (append L (list (getreal "\n L: "))))

   )

   (setq wReaz nil)
   (repeat nSup

       (setq wReaz  (append wReaz (list (getreal "\n Support: "))))

   )

   

   (setq pStart (getpoint "\n Start Point"))
   (df)
   (command "pline" p0 p1 p2 p3 "")
)   


(defun dtr (x)
   (* pi (/ x 180.0))

)    



(defun df ()
(setq wReazP2 (car L))
(setq p1 pStart)
(setq p0 (polar p1 (dtr 0.0) (wReazP2)))
(setq p2 (polar p1 (dtr 270.0) (hReaz)))
(setq p3 (polar p2 (dtr 0.0) (wReazP2)))
)

(princ)

Link to comment
Share on other sites

(defun c:Grinda()

   (setq bBeam (getdist    "\n bBeam: "))
   (setq hBeam (getdist    "\n hBeam: "))
   

   (setq hSup   (* 3 hBeam))

   (setq nOp (getint "\n No.Op. "))
   (setq nSup (+ nOp 1))

   (setq L nil)
   (repeat nOp

       (setq L  (append L (list (getreal "\n L: "))))

   )

   (setq wReaz nil)
   (repeat nSup

       (setq wReaz  (append wReaz (list (getreal "\n Support: "))))

   )

   

   (setq pStart (getpoint "\n Start Point"))
   (df)
   (command "pline" p0 p1 p2 p3 "")
)   


(defun dtr (x)
   (* pi (/ x 180.0))

)    



(defun df ()
(setq wReazP2 (car L))
(setq p1 pStart)
(setq p0 (polar p1 (dtr 0.0) (wReazP2)))
(setq p2 (polar p1 (dtr 270.0) ([color="Red"]hReaz[/color])))
(setq p3 (polar p2 (dtr 0.0) (wReazP2)))
)

(princ)

 

 

For starters you have this:

 

 

 (defun df ()
 (setq wReaz[color="Red"]P2[/color] (car L))
 (setq p1 pStart)
 (setq p0 (polar p1 (dtr   0.0) (wReaz[color="red"]P2[/color])))
 (setq p2 (polar p1 (dtr 270.0) ([color="Red"]hReaz[/color])))
 (setq p3 (polar p2 (dtr   0.0) (wReaz[color="red"]P2[/color]))))

(princ)

 

 

I think the P2 needs to go since you do not have a variable of that name.

There is still another problem that I am checking. Also hReaz does not seem correct since I only see wReaz.

You are calling variables that do not exist in the code.

Link to comment
Share on other sites

hreaz is actually hbeam (my bad :D) and wReazP2 is the name of a variable.

 

You have this above:

   (setq [color="red"]wReaz[/color] nil)
 (repeat nSup
   (setq [color="Red"]wReaz[/color]  (append [color="red"]wReaz [/color](list (getreal "\nSupport: ")))))

Link to comment
Share on other sites

You have this above:
   (setq [color="red"]wReaz[/color] nil)
 (repeat nSup
   (setq [color="Red"]wReaz[/color]  (append [color="red"]wReaz [/color](list (getreal "\nSupport: ")))))

Sorry about that, I see now.

Link to comment
Share on other sites

Why set wReaz nil? Its not in the same loop as L.

 

   (repeat nOp
   (setq L  (append L (list (getreal "\nL: ")))))
 [color="Red"](setq wReaz nil)[/color]
 (repeat nSup
   (setq wReaz  (append wReaz (list (getreal "\nSupport: ")))))

 

 

I am not sure what you are trying to do here.

Link to comment
Share on other sites

Wreaz (wbeam) is set to nil because without it i get an error inside the loop when trying to append a new value. It should work without it, but for some reason it does not. Don't know why.

Link to comment
Share on other sites

Wreaz (wbeam) is set to nil because without it i get an error inside the loop when trying to append a new value. It should work without it, but for some reason it does not. Don't know why.

As I said, You have two separate loops.

 

L will execute first the number of times required.

Then wReaz will execute the number of times required.

 

You still have not told me what bBeam is for yet.

 

What is this code suppose to do?

Can you post a sample drawing?

You are only showing four points that need to be drawn in the pline command,

But you are repeat looping and appending a list. Whats up with that?

Maybe there is a simpler approach to what you are trying to do.

Link to comment
Share on other sites

I have to draw a beam like the one in the given image. More correctly, i have to implement a script that when run will draw the beam based on user input.

As I have said, in lisp I'm a newbie..I understand it but am for now i'm not as familiar with it as i should be.

I had an app in C# that did every-part of beam design and calculus, that allowed the user to export the plans in to Autocad as DXF files. Due to compatibility issues..and also because it is to be used internally and only to speed up the drawing of some elements in Autocad, I'm now scripting in Autolisp.

 

The way I thought about it is like this. Let the user enter firstly the basic data, such as the width of the beam (bBeam), the height of the beam (hBeam), the number of openings in the beam (nOp). The number of supports is nSup=nOp+1, and then the user enters data like the length of each opening (this is where L is used) and the width of each support (wReaz or wSup). After the data is entered, to simplify the routine, 3 functions are called. One is df that stands for drawFirst. This one draws the left half of the left-most support. The 3rd one draws the right half of the right-most support. The second one is used to draw what is in between (if you imagine having only one opening, hence 2 supports, the second function draws the second half of the left-most support, the opening and the first half of the final support). The second function is called repeatedly for nOp times. The start point of the drawing is considered the top-left point of the first support, and is used as reference and given by the user.

For now, the data is entered using the command prompt in autocad, but in the end i'll be using DCL.

 

Shuuuuu, That's about it. Now why do i get that error when calling (df)?

Untitled-1.jpg

Link to comment
Share on other sites

I have to draw a beam like the one in the given image. More correctly, i have to implement a script that when run will draw the beam based on user input.

As I have said, in lisp I'm a newbie..I understand it but am for now i'm not as familiar with it as i should be.

I had an app in C# that did every-part of beam design and calculus, that allowed the user to export the plans in to Autocad as DXF files. Due to compatibility issues..and also because it is to be used internally and only to speed up the drawing of some elements in Autocad, I'm now scripting in Autolisp.

 

The way I thought about it is like this. Let the user enter firstly the basic data, such as the width of the beam (bBeam), the height of the beam (hBeam), the number of openings in the beam (nOp). The number of supports is nSup=nOp+1, and then the user enters data like the length of each opening (this is where L is used) and the width of each support (wReaz or wSup). After the data is entered, to simplify the routine, 3 functions are called. One is df that stands for drawFirst. This one draws the left half of the left-most support. The 3rd one draws the right half of the right-most support. The second one is used to draw what is in between (if you imagine having only one opening, hence 2 supports, the second function draws the second half of the left-most support, the opening and the first half of the final support). The second function is called repeatedly for nOp times. The start point of the drawing is considered the top-left point of the first support, and is used as reference and given by the user.

For now, the data is entered using the command prompt in autocad, but in the end i'll be using DCL.

 

Shuuuuu, That's about it. Now why do i get that error when calling (df)?

Try this:

 

(defun df ()
 (setq wReazP2 (car L))
 (setq p0 pStart)
 (setq p1 (polar p0 (dtr   0.0) wReazP2))
 (setq p2 (polar p0 (dtr 270.0) hbeam))
 (setq p3 (polar p2 (dtr   0.0) wReazP2))) 

 

It now draws something, Not sure what.

Link to comment
Share on other sites

Try this:

 

(defun df ()
 (setq wReazP2 (car L))
 (setq p0 pStart)
 (setq p1 (polar p0 (dtr   0.0) wReazP2))
 (setq p2 (polar p0 (dtr 270.0) hbeam))
 (setq p3 (polar p2 (dtr   0.0) wReazP2))) 

 

It now draws something, Not sure what.

Or this:

 (defun df ()
 (setq wReazP2 (car L))
 (setq p1 pStart)
 (setq p0 (polar p1 (dtr   0.0) wReazP2))
 (setq p2 (polar p1 (dtr 270.0) hbeam))
 (setq p3 (polar p2 (dtr   0.0) wReazP2)))

 

Sorry I had moved the points in the previous post.

Link to comment
Share on other sites

:)) I see it now. Thanks for your help and, more importantly, patience.

Not a problem, There were just a few things that seemed puzzling. I was expecting the worst when the problem was really simple. I assume there will be more coding, So you are doing this in some kind of stage. If car is getting the first distance in the list, Then most likely other calculations will follow for the remaining distances in that list.

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