PDA

View Full Version : Lisp help needed


jameshetfield
02-02-2004, 12:19 AM
Hello evrybody!
I am a relatively new user to working on Lisp in CoCreate and i wanted some assistance for a particular problem.
I have been trying to generate a polygon with an arc on top,using parametric coordinates,i.e,say for eg.,i have n sides of a polygon,and i want an arc on top.The option i am looking to use for arc is "center",wherein i need to input the 2 end points of the arc parametrically (i dont know the coordinates).Does anybody have a function for this or any suggestions?

Eagerly waiting for a reply,
Bye
James

John Scheffel
02-02-2004, 09:35 AM
I don't have any LISP code to offer, but here are some tips that may help you.

You can use the unsupported Recorder function to record manual creation of your desired geometry and study it to see the functions and commands that were used. You can load the recorder with the command

(load "recorder")

This will add a button to your Toolbox to open a dialog which can be used to control the recorder. You can then use a text editor such as notepad to study the recorded files.

Once you know which functions and commands were run, you can also use the standard Windows Find/Search to find documentation on them. Right click on the "help" folder directly under the main Modeling install folder (OSD_Modeling_x.x.x.x) and select Find or Search. Then search for files containing the text string of the command.

Thom Ivancso
02-02-2004, 10:49 AM
How are you generating the polygon?

What information is required to be inputted by the user?

It sounds like you are looking to draw an arc from the polygon center going through two of the polygon circumference points.

jameshetfield
02-02-2004, 09:06 PM
Thanks Thom and John,but to reply to Thom:

The user input will be the dia,and the 2 end points (which i shall pick) of the polygon (say for eg., the 3 sides of a rectangle).
The code should take the center of the arc and create the arc. Hence i wanted something which would automatically take the center.

Any suggestions?
regards
james

jameshetfield
02-02-2004, 09:59 PM
John,
Is the "recorder" same as the record macro facility (Customize-New-Record)?
If it isn't please tell me how it works.I have loaded the dialog box into the toolbox using the command u gave, but how do u use the text editor? Could u please give me a procedure for it?

Thanks
James

Andy Poulsen
02-03-2004, 06:27 AM
Hi James,

The Recorder function is not quite the same as the Customize->New->Record. They both record commands, but the first is designed simply to capture the commands to a file (such as for programming help like John suggested), and the second is designed to automate a repetitive task and store those commands so they can be run by clicking on a toolbar button.

The Recorder function (in the toolbox) is most likely the one that would help you the most, as it will allow you simply to save the executed commands to a file. You choose a filename where you wanted the commands list to be stored, and click "Start", then click through the command sequence, and click "Stop", at which point the commands will be written into the file you chose at the beginning. You can then open this file from Windows explorer (for instance) using any text editor (such as Notepad, etc).

I am attaching a bit of code that should give you some ideas about how to accomplish what you wish. I have included many comments so you can know exactly what is happening, and have also put in some simple error checking that you may want to include (such as requiring the diameter to be at least as large as the distance between the points). I have set this up so that the arc will go counter-clockwise from the first point to the second so that it's always consistent (picking the points in the reverse order will change the direction of the arc).

Just load the attached lisp file into your OSD Modeling session. Save it to a known location on your hard drive first, and then do one of the following:

1. Simply drag the file from a windows explorer window into your OSDM session.

2. in the command line of your OSDM session, type (load "arc-sample.lsp") or (load "c:/temp/arc-sample.lsp") replacing "c:/temp" with the directory where you saved arc-sample.lsp (Note -- use the unix-standard forward slash "/" to separate directories rather than the windows-standard backslash "\" -- you'll get unexpected results if you don't).

3) in your OSDM session, click File->Load... Then browse to the directory where you saved arc-sample.lsp, set the file type to "Lisp Source (*.lsp)" select the file, and click "Load"

After the file is loaded there will be a new button called "Arc Sample" in your toolbox that you can play with to see how it works, and you can look at the lisp file using your favorite text editor as mentioned above.

Please let me know if you have any questions.

Good luck, and enjoy!

Andy

jameshetfield
02-03-2004, 11:54 PM
Hello andy,
Thanks a lot for that info!..and the lisp works well.In fact,the code i have also does the same thing except constraining the dia to the dist b/w the 2 points (did not think of that!!!).

But in this particular process, the center position of the arc is dependent on the diameter value and the 2 points which are inputs. What if i need to keep the center at a predefined position?Not by coordinates,but in a function.

Lets say,I need to keep the center at a particular position.For eg., if i have 3 sides of a polygon and i need an arc joining the top 2 points of the open side,with the center at exactly half the dia value(y coord) and half the base width value(x coord),i.e,the total height of the profile would equal the diameter. Can i pass values like: center (/ width 2),(/ diameter 2).? What i am looking at is giving only the dia value; it should take the center automatically along with the end points.

Please suggest!
Bye
james

jameshetfield
02-06-2004, 08:37 PM
152 views and no one seems to be having any ideas for this!:(
anyways,thanks to all who've tried to help!I hope i get it someday.
regards,
james

dorothea
02-09-2004, 07:23 AM
Hi James,

I have to admit that I didn't get the point, where the center should be. But if you just want to create a point out of (/ width 2) and (/ diameter 2) can can do it like this:

(setf center (make-gpnt2d :x (/ width 2) :y (/ diameter 2)))

For sure you first have to calculate 'width' and 'diameter'.

I don't know it this helps you at all. It was just a try.

Dorothea

jameshetfield
02-09-2004, 09:41 PM
Hi dorothea!
thanks for helping me out on this.This probably would work if i give the points also as inputs.But lets say, I need to define the 2 end points too (parametrically) in geometric terms, as in, in trigonometric functions (sine and cosine). Hence the only input would be the diameter and the function should automatically take the 2 end points and center and draw the arc. I hope i am clear.
Please tell me if u need clarifications.
Bye
james

dorothea
02-09-2004, 09:51 PM
Hi James,

So this means you just have a diameter and a polygon? Could you please make a screenshot of the geometry you have and the desired resulting arc? This would help me understanding the problem.

Dorothea

jameshetfield
02-09-2004, 11:55 PM
Yes exactly!
As given in the image,i just have the polygon,and the arc on top which is getting connected by the 2 end points of the side arms. I have generated the polygon and am creating the arc by picking the points and entering a diameter value. I would like to give only the diameter and the function should automatically take the 2 end points and the center as defined geometrically,taking the dia equal to the total height of the profile.

dorothea
02-10-2004, 12:26 AM
Hi James,

I hope the attached lisp file will bring you a step further to what you want.
Load the file and you'll get a button in the toolbox. The dialog demonstrates how to find the open ends of the polygon within the current wokplane. This way you should be able to avoid picking the open ends manually.
Can you get all other things out of the previous posted lisp file from Andy?

Dorothea

jameshetfield
02-10-2004, 01:27 AM
Hello dorothea,
Thanks for trying that out, but unfortunately, it doesn't really help me,cause the output is just that it highlights the open ends.Point is how do i integrate it with my lisp code at runtime?

What i need is a lisp syntax where i can trigonometrically define a particular point (say, the end of one of the side arms) in terms of the origin ,which is the lower left point of the horizontal line. I have the angle and the length of the side arm,i just need to define the coordinates of the end point in terms of sine and cosine,and pass it as parameters.Same with the other point,and the center (as defined by you).

Hope this helps to understand.
Regards,
james

P.S: I have tried using sine,cosine/asin,acos/asine,acosine,but nuthing really works.Actually speaking,i am not sure what's the correct syntax to be used for such kinds of definitions.

Thom Ivancso
02-10-2004, 02:01 AM
Hello James,

Could you post the Lisp code you have written so far for generating the polygon?


Cheers
Thom

jameshetfield
02-10-2004, 03:14 AM
Hi Thom,
I have attached the lisp file. Please go thru it. As u would see,i pick the points (point1 and point2) which are the end points for the 2 sidearms.The "point" is for the end of the horizontal base (cudn't find a way to do it automatically).I needed the dia input of the arc equal to the height of the profile which gets generated.

Thanks,
Regards
James

jameshetfield
02-15-2004, 10:42 PM
Hello Thom!
I attached the lisp code,but no one seems to have much time.
Am still expecting some help in this regard.
Regards,
james!

Thom Ivancso
02-16-2004, 07:41 AM
Hello James,

Got your code and I am looking into it. I let you know if I come up with anything helpful.

Cheers
Thom

jameshetfield
02-16-2004, 08:02 PM
Thanks a lot Thom!
Am looking forward to hearing from you!
Regards,
James

jameshetfield
02-21-2004, 04:26 AM
Hello all!
no one seems to be having any ideas on this...this thread's going old..I, for one, am out of ideas.....
anyone out there trying it out?
PLease!
Thanks
james

Thom Ivancso
02-24-2004, 04:02 PM
Hello James,

I have looked at your code and think I have found a way to find the two end points of the lines and the center of the diameter specified. It's got a good bit of math involved in it to make it work with your example.

The only problem I see with my solution is that your code allows for a user to technically make a straight line using three segments.

From your image posted you have a channel shape with an arc on it. Is this the only shape you want this lisp routine to create.

Also I noticed in running the code you place the first segment from 0,0 at a 0 degree to the length specified, then the second segment starts at 0,0 the new angle specified and then the length, the final segment is then open game to the user he can pick the 0,0 point again or the open end of the second segment or the open end point of the first segment.

This makes it hard to control the math to make the arc automatically using the end points and the arcs figured center point.

If I am incorrect with my thoughts on this please let me know.

If the routine had a little more control as to what the user can or can not input it might work better.

Hope this helps, I would need to clean up the code before I would send it to you. Let me know what you wish to do.

Cheers
Thom

jameshetfield
02-24-2004, 07:39 PM
Yes thom!
U're right.The way my code was working was actually because I did not know how to catch the end point of the first segment to be able to give the angle and length of the side arm.

Basically,with respect to the old code,what i was doing:
1.Defined an origin (which can be changed by picking up the point again).
2.Gave the length for the first segment.
3.Code then takes the origin and asks for angle and length of the side arm.
4.And then,I cudnt find a way to automatically pick the end point of the first segment,so i ask the user to pick the point,and then give the angle and length of side arm.
5.Same thing I do with the arc (Pick both end points and give the dia).

Now,What i wanted to do actually:
The only amount of "mousework" would be in the first step,i.e in picking any point for the origin.From then on,the inputs I would be giving would be:
1.Length of the base line and Angle and length of the sidearms.
2.The Diameter of the arc,the diameter being equal to the total height of the profile.

I do realise the amount of math involved,cause I too did a fair bit of the same,and thats why I wanted to know about the gonometric inputs within a function (sin,cosine,etc).But in any case,it would be nice if you could just tell me a little about the math u went thru,so that i cud compare it with mine.

....................................................................................................
If the routine had a little more control as to what the user can or can not input it might work better.
....................................................................................................

Could you please tell me what control were you trying to refer to here?

.....................................................................................................
Is this the only shape you want this lisp routine to create.
.....................................................................................................
For the moment,yes!..Of course seeing your code I shall learn a lot regarding defining functions and hence can work on more shapes and stuff.

I hope this helps.I'm thankful that you are still on it.Gives me lot of heart!!..
bye
Regards
James

jameshetfield
02-29-2004, 08:15 PM
Hello Thom!
Hopefully,something's coming up on the code.

If possible,could you please post your code so that I could try that out and then proceed further?

Regards,
James

Thom Ivancso
03-02-2004, 09:22 AM
Hello James,

I have re-written the Lisp routine, please check it out.


Cheers
Thom

jameshetfield
03-03-2004, 03:48 AM
Hello Thom!
The code works fine.There was a small correction which had to be made, but otherwise it works fine and it's given me a lot to learn,especially passing parameters.

Now,i just wanted to discuss on this,if it's ok:
What your code does is that it eliminates the input of diameter,which is why you took the coordinates of the center of the arc to be x: dist/2 :y 0. Let say,I need the diameter to be of some particular value;that means I dont have control over the position of the center right?
Please tell me if what I want is plausible:
I need to be able to input a dia value, as well as make the center to be defined at x: dist/2 y:dia/2. I am trying it out and shall tell you if i can do it. But please tell me if I can do it the way I have described?

Looking forward to your reply,

Bye and thanks,
Regards,
James

jameshetfield
03-07-2004, 10:57 PM
Hello thom!
As i mentioned in the previous post, I was trying to make a few modifications and i have attached a piece of lisp code for that.

What I am doing here is:

a) Eliminate control over the end points and the center of the arc. I am not defining them.

b) The only inputs I am providing is the arc dia and the angles of begin and end;essentially,i am using the "arc :cen_rad_ang" option to create the arc.

c) I am picking the center of the arc randomly anywhere in the active plane.

Now,while I am doing this, I am facing a problem:
When i measure the angles between the end points,the value does not correspond to the input I have given. I have tried to put in 80 and 100 degrees as start and end angles and the value between the end points comes to some other value (in decimals that too!),whereas,the value should be 20 degrees.

I have not found anything wrong in the code. Could you please go thru it and check it and tell me whats wrong?

Looking forward to a reply,
Thanks for your time!
James

dorothea
03-08-2004, 06:48 AM
Hi James,

I have more a general comment than a particular fix for your problem.

When writing your own code you have to work with INTERNAL units. The developers kit always works with these units. The system does the conversion from user units to internal units for you. Especially when working with angles you'll run into problems because the user units are often degree and the internal units are radian.
You specify the value type of a variable defining an angle as :positive-length. This means you have to perform the units conversion by yourself. When you call the 'arc' dialog you have to pass the values in radian.

Other possibility is to use the build in conversion as I mentioned before. Just change the value-type to :angle.

Please check also the documentation:
help/Common/documentation/integration_kit/reference/dg_manual.html#numbers



Dorothea

jameshetfield
03-08-2004, 07:39 PM
Thanks a lot dorothea!
I completely overlooked the "value-type :positive-length" part in the code!!...brain-clouds form too often nowadays..:) ....
Anyways,thanks again for that tip!! I am trying out a creation of a profile,and I hope I can turn to experts like you whenever I face a problem, 'cause, I am learning CoCreate Lisp on my own,and I dont have any other resource than this forum and the help maunals.

Of course,if someone could tell me how's the correct manner to go through the manual,it will save a lot of time.

Expecting a reply soon,
Regards,
James

jameshetfield
03-09-2004, 12:21 AM
Hello Dorothea!
As i had said, I have been trying out a profile creation in cocreate lisp. I have run into an issue again, and I have attached the code for you to check:

Just for your info, P1 and P4 are the points on the right side of the vertical construction line, and P2 and P3 are the points on the left side. I have defined the points trigonometrically, but somehow when I am creating a line between P2 and P3, it is not catching P2. There's nothing wrong with the logic (as i see it now),cause it catches P1 and P3 and forms a line. Dont know why it does not catch P2 :confused: .

Also, I tried mirror option,but I am not sure about the syntax.What I did was:
(defun draw-profile()
(let ((rad (/ dia 2)))
(sd-call-cmds (arc :cen_rad_ang 0,0 rad ang1 ang2))
(sd-call-cmds (c_line_inf :vertical 0,0))
(setq l1 (c_line_inf :vertical 0,0))
(sd-call-cmds (c_line_inf :horizontal 0,0))
(setq p5 (make-gpnt2d :x 0 :y (-(/ dia 2))))
(sd-call-cmds (c_line_inf :horizontal p5))

(setq sin_p1 (sin ang1))
(setq cos_p1 (cos ang1))
(setq x_p1 (* rad cos_p1))
(setq y_p1 (* rad sin_p1))
(setq p1 (make-gpnt2d :x x_p1 :y y_p1))
(setq p4 (make-gpnt2d :x dia :y (- rad)))
(sd-call-cmds (line :two_points p1 p4))
(setq l2 (line :two_points p1 p4))

(mirror_2d l2 :horizontal l1 :repeat_factor 1 :keep :on)
)

)

Whats going wrong?
Looking forward to a reply,
Regards,
James

dorothea
03-15-2004, 09:22 PM
Hi James,

I will not fix any of your mathematical calculation because I don't understand what's going on. Where I can help you is only finding problems in coding if they are of general nature.

As I said in my previous reply, the program internally works with internal units and not with user units. This includes RADIAN for ANGLE.
You write in your code
(setq sin_p2 (sin (- 180 ang2)))
Do you mean PI instead of 180 degree?

What did you mean with the posted code in the text? Where is the problem, or what doesn't work? I only had a look into the attached lisp file.
And there I saw that you do not declare all used variables. What about for instance ang1 or sin_p1? You assign values in the dialog and/or function but are they supposed to have global influence or should they just be local variables? This might lead to problems because you change the value of such variables without knowing it.


Hope this helps,
Dorothea