Jump to content

Road alignment drafting problem using lisp routine


aloy

Recommended Posts

I have a list given below:

(setq l '((0.0 (298.546 228.499 0.0)) (20.0 (316.873 236.508 0.0)) (40.0 (335.2 244.516

0.0)) (60.0 (353.526 252.524 0.0)) (76.7565 (368.881 259.234 0.0)) (80.0

(371.853 260.533 0.0)) (100.0 (390.094 268.732 0.0)) (120.0 (407.932 277.769

0.0)) (126.756 (413.792 281.131 0.0)) (140.0 (425.028 288.076)) (140.0 (441.616

299.307)) (160.0 (457.594 311.333)) (180.0 (472.95 324.142)) (200.0 (487.648

337.704)) (220.0 (501.649 351.982)) (240.0 (514.919 366.943)) (260.0 (527.424

382.54)) (280.0 (539.135 398.759)) (300.0 (550.02 415.535)) (320.0 (560.053

432.834)) (320.916 (560.492 433.63)) (340.0 (568.86 450.673 0.0)) (360.0

(576.592 469.116 0.0)) (370.916 (580.594 479.272 0.0))))

When it is loaded and run with the code below the line segents drawn are not as expected. What seems to be the problem

 

(setq p1(cadr (car l)))

(while (/= l nil)

(setq l(cdr l))

(setq p2(cadr (car l)))

(command "line" p1 p2 "")

(setq p1 p2)

)

Edited by aloy
As advised
Link to comment
Share on other sites

I suspect that is an interference with current Osnap mode – please adjust you code as below and see if help:

 (command "[color=red]_[/color]line" [color=red]"_NON"[/color] p1 [color=red]"_NON"[/color] p2 "")

Link to comment
Share on other sites

Welcome to CADTutor :)

 

Object Snap may be affecting your use of the Line command, causing points to jump to the nearest osnap point. To avoid this, use "_non" to ignore Object Snap when supplying points.

 

Here are some alternatives to your code:

 

(while (cadr l)
   (command "_.line" "_non" (cadar l) "_non" (cadadr l) "")
   (setq l (cdr l))
)

(mapcar '(lambda ( a b ) (command "_.line" "_non" (cadr a) "_non" (cadr b) "")) l (cdr l))

 

Edit: Added "" to Line Command - thanks pBe!

Edited by Lee Mac
Link to comment
Share on other sites

I'd tried to clean up your code a bit:

 


(defun c:test (/ l p1 p2)

(setq l '(
 (0.0 (298.546 228.499 0.0)) 
 (20.0 (316.873 236.508 0.0)) 
 (40.0 (335.2 244.516 0.0)) 
 (60.0 (353.526 252.524 0.0)) 
 (76.7565 (368.881 259.234 0.0)) 
 (80.0 (371.853 260.533 0.0)) 
 (100.0 (390.094 268.732 0.0)) 
 (120.0 (407.932 277.769 0.0)) 
 (126.756 (413.792 281.131 0.0)) 
 (140.0 (425.028 288.076))   
 (140.0 (441.616 299.307) ) 
 (160.0 (457.594 311.333)) 
 (180.0 (472.95 324.142)) 
 (200.0 (487.648 337.704)) 
 (220.0 (501.649 351.982)) 
 (240.0 (514.919 366.943)) 
 (260.0 (527.424 382.54)) 
 (280.0 (539.135 398.759)) 
 (300.0 (550.02 415.535)) 
 (320.0 (560.053 432.834)) 
 (320.916 (560.492 433.63)) 
 (340.0 (568.86 450.673 0.0)) 
 (360.0 (576.592 469.116 0.0)) 
 (370.916 (580.594 479.272 0.0))))

 (while (> (length l) 1)
        (setq p1 (cadr (car l)))
        (setq p2 (cadr (cadr l))) 
        (command "line" p1 p2 "") 
        (setq l (cdr l)))
(prin1))

 

See if that helps. -David

Link to comment
Share on other sites

aloy,

 

Please read the CODE POSTING GUIDELINES and edit your post.

 

I moved this thread to the AutoLISP, Visual LISP & DCL forum.

 

 

Thanks for the advice. The codes used to generate the horizonal alignment which includes straight sections, spirals and circular curves which was developed over 20 year ago using AutoCAD v. 1.2 is also mine. These programs were used to generate verticle alignments, long sections, cross sections and earthworks calculations. Some highways were built using them. Since I moved to other areas of civil engineering I did not have the opportunity to further develop them. My attempt now is to develop programmes to design the geomatric elements according to Uk's TD 9, TD 22 etc. interactively on a topo plan in Autocad. In this connection, I have already received help in this forum and I am gratful for that.

Aloy

Link to comment
Share on other sites

Hi David,

Thaks for the reply. However it did not work. From the replies in this forum, I realised that the problem is due to the object snap being on during the exection. My code given in the posting works when the object snap is off.

Redards,

Aloysius. H

Link to comment
Share on other sites

Hi Lee Mac,

Thanks for the reply. However the code did not work. I remember using lambda fuctions more than twenty years ago when I was developing a routine for earthworks calculations. It was very useful and there were no internet then. I had to do reseach work in British council Library to 'discover' them.

My code in the posting works when object snap is off.

Regards,

Aloysius. H

Link to comment
Share on other sites

Hi Mircea,

Thanks for the help. It worked when using the code sugested by you. It also works with the code in my posting when object snap is off.

Regards,

Aloysius.H

Link to comment
Share on other sites

Inputting "_NON" before supplying points is in fact overriding the current Osnap settings with None mode; is equivalent with setting Osnap to Off, but you don't need to pay attention to manage it manually (set Off before running the routine, restoring it later).

Alternatively, when the code is more complex, to don’t have to pay attention to add the "_NON" each time is required, you can retain current Osnap value (system variable OSMODE), disable it, run your code and restore it with the previous value before exit.

(setq myOsm (getvar "OSMODE"))
(setvar "OSMODE" 0)
;;; code
(setvar "OSMODE" myOsm)

An advanced solution that isn't affected by current Osnap is to directly add or modify the entities into drawing's database - please check the ENT* functions family.

Link to comment
Share on other sites

Hi Lee Mac,

Thanks for the reply. However the code did not work.

 

Which code did you test? The while loop or the mapcar iteration? What error do you receive, if any?

 

Looking back at both of my examples, I don't see why it should fail...

Link to comment
Share on other sites

maybe...

    (command "_.line" "_non" (cadar l) "_non" (cadadr l) [b][color=blue]""[/color][/b])

 

Ah yes, of course! Thanks pBe, I have updated my earlier code :)

Link to comment
Share on other sites

Sorry, Lee Mac,

I only hand copied the two codes. When I copied and pasted, the mapcar worked very well. How ever in both occations the while loop did not draw anything and the list emptied.

Thank you very much for welcoming me to the forum.

Aloy

Link to comment
Share on other sites

Welcome to CADTutor, aloy!

 

FWIW -

 

You may want to consider (if you haven't already), asking your employer to provide you with an AutoCAD Vertical such as Civil 3D, given that you're needing to do roadway alignments, etc... My $0.02, anyway. :thumbsup:

Link to comment
Share on other sites

Thank you, RenderMan.

I am from a third world country, working in a rich fairly developed one from ASEAN, now on my own. I wanted to see how civil- 3D look like and tried to down load a trial pack on the internet. My connection needed 7 hours and I gave up. I have a reasonable knowledge on the design process and have samples of drawings generated by expensive packages. These packages run on their own platforms. My aim is to develop something that can run in AutoCAD and is also affordable to an engineer or a small company from a third world country. Are there any other cheap version that can run inside AutoCAD and generate drawings needed?.

Regards,

Aloy

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