Jump to content

Lisp file needing some help.


Recommended Posts

Posted
In any case, I have enjoyed the deviation in this thread, and I hope my earlier posts aren't wasted.

 

Lee,

 

Honestly I did get quite a bit from it. The stuff you shown was worth the trouble even if the direction intended was different. I myself tend to overbuild things, But in my time I eventually get the picture. I just get the feeling sometimes that people will over do things in such a way and since I have been there myself I will question methods used.

 

It was not a waste at all.

  • Replies 37
  • Created
  • Last Reply

Top Posters In This Topic

  • The Buzzard

    19

  • Lee Mac

    8

  • laisonalbarado

    8

  • alanjt

    1

Posted

I have just revised and reran the an I got a:

 

Select 1st object:

Enter second point:

error: no function definition: GETDISTANCE

 

Here is what the code looks now:

 

;;Moves and object in a parallel plane of another until it is perpendicular
;;to it then rotates 1st object so that it lines up with it. Similar to 
;;align command.
;;Written by Laison Albarado 11-09-2011 
(defun c:rm (/ pt1 pt2 pt3 pt4 pt0 ang1 dst1)
(setq os (getvar "OSMODE")) ;Save User Object Snaps
(setvar "OSMODE" 8359)
(setq pt1 (getpoint "\nSelect 1st object: ")) 
(setq pt2 (getpoint pt1 "\nEnter second point: "))
(setq pt1 (getdistance "\nEnter Distance are select item: "))
(setvar "OSMODE" 8359)
(Setq pt3 (getpoint pt1 "\nSelect Reference point/object: "))
(command
"move" pt1 pt2
(setq ang1 (getangle pt1 pt3))
(setq pt4 (polar pt2 ang1 dst1)) 
(command 
"rotate" pt1 pt3
(setvar "osmode" os) ;Restore your Saved User Object Snaps
)
)
)

 

Could you tell me the difference between these 2:

 

(setq pt2 (getpoint pt1 "\nEnter second point: "))

 

(sds_getpoint(NULL,"\nSelect first point for distance: ",firstpt)
          (sds_getpoint(firstpt,"\nSecond point: ",secondpt)

Posted

No such command as getdistance, Try getdist. If you are not certain, Refer to the developer help section in AutoCAD.

Posted

By the way, No need to set OSMODE twice unless you are turning it off at some point and want it turn on again.

 

;;Moves and object in a parallel plane of another until it is perpendicular
;;to it then rotates 1st object so that it lines up with it. Similar to 
;;align command.
;;Written by Laison Albarado 11-09-2011 
(defun c:rm (/ pt1 pt2 pt3 pt4 pt0 ang1 dst1)
(setq os (getvar "OSMODE")) ;Save User Object Snaps
[color=red](setvar "OSMODE" 8359)
[/color](setq pt1 (getpoint "\nSelect 1st object: ")) 
(setq pt2 (getpoint pt1 "\nEnter second point: "))
(setq pt1 (getdistance "\nEnter Distance are select item: "))
[color=red](setvar "OSMODE" 8359)   ;Remove this
[/color](Setq pt3 (getpoint pt1 "\nSelect Reference point/object: "))
(command
"move" pt1 pt2
(setq ang1 (getangle pt1 pt3))
(setq pt4 (polar pt2 ang1 dst1)) 
(command 
"rotate" pt1 pt3
(setvar "osmode" os) ;Restore your Saved User Object Snaps
)
)
)

Posted

One more thing, The command calls require some fixing.

 

I am a bit uncertain of what you are doing, But maybe something like this:

(command "._move" "_l" pt1 pt2)
and
(command "._rotate" "_l" pt1 ang1)

Posted

What is this for?

(setq pt1 (getpoint "\nSelect 1st object: ")) 

 

 

Do you want a point? or Do you want to select an entity?

Posted

I am still receiving still error:

 

Select 1st object:

Enter second point:

error: no function definition: GETDISTANCE

Posted
I am still receiving still error:

 

Select 1st object:

Enter second point:

error: no function definition: GETDISTANCE

 

Did you change to getdist?

Maybe you may need to exit AutoCAD and restart.

Posted
I am still receiving still error:

 

Select 1st object:

Enter second point:

error: no function definition: GETDISTANCE

 

YES , there is nothing called (GETDISTANCE) just replace it with (getdist) . come on.

Posted

A bit more confusion here:

 

;Is this correct
(setq [color=red]pt1[/color] (getdist "\nEnter Distance are select item: "))
;or should it be
(setq [color=red]dst1[/color] (getdist "\nEnter Distance are select item: "))

 

Please decide what your variables are suppose to get.

You have dst1 later in your code and no value to it.

 

I made mentioned all of these issues in post 7.

Posted (edited)

laison,

 

I did not fully understand what or how you were trying to resemble the align command. Here is a code I put together to somewhat resemble the align command, But not exactly. I provided the attached RM.dwg below for you to test it out. Just follow the prompts in the code. What you do with this code later is up to you. This is only to give you an idea. Later you can make this code more complicated by filtering for certain objects types. You can also reduce the number of prompts required. I set it up the way I did to give you a better understanding of how to select the object. How to supply the prompts to get input, And how to manipulate the object. You can rewrite it to your liking if you wish.

 

Complication comes later as you get better at this.

 

 

Pseudocode: http://en.wikipedia.org/wiki/Pseudocode

The drawing has two (2) flange blocks.

1. Select the flange to be moved and rotated.

2. Supply the four points requested by the program.

3. Calculate the angle from radians to degrees.

4. Manipulate the flange to be moved to the flange to be aligned to.

 

 

[color=blue];;Moves an object in a parallel plane of another until it is perpendicular[/color]
[color=blue];;to it then rotates 1st object so that it lines up with it. Similar to [/color]
[color=blue];;align command.[/color]
[color=blue];;Written by Laison Albarado 11-09-2011 [/color]
;
(defun C:RM (/ DEG DPT1 DPT2 ENT OS RAD SPT1 SPT2)             [color=blue];Declare local variables[/color]
 (setq OS (getvar "osmode"))                                  [color=blue];Save User Object Snaps[/color]
 (setvar "osmode" 8359)                                       [color=blue];Set object snaps[/color]
 (setq ENT  (ssget)                                           [color=blue];Select entity[/color]
       SPT1 (getpoint "\nSpecify first source point: ")       [color=blue];Get Source Point 1[/color]
[color=black]        DPT1 (getpoint "\nSpecify first destination point: ")[/color]  [color=blue];Get Destination Point 1[/color]
       SPT2 (getpoint "\nSpecify second source point: ")      [color=blue];Get Source Point 2[/color]
       DPT2 (getpoint "\nSpecify second destination point: ") [color=blue];Get Destination Point 2[/color]
       RAD  (angle DPT1 DPT2)        [color=blue];Get angle in radians DPT1 to DPT2[/color]
       DEG  (RTD RAD))               [color=blue];Convert radians to degrees[/color]
 (command "._move" ENT "" SPT1 DPT1) [color=blue];Move Enitiy from SPT1 to DPT1[/color]
 (command "._rotate" ENT "" DPT1 DEG);[color=blue]Rotate Enitity on basepoint DPT1 to degrees[/color]
 (setvar "osmode" OS)                [color=blue];Restore your Saved User Object Snaps[/color]
 (princ)                             [color=blue];Exit quietly[/color]
)                                     [color=blue];End defun[/color]
(princ)
;
(defun RTD (RAD)(* 180.0 (/ RAD pi))) [color=blue];Convert radians to degress[/color]
;

RM.dwg

Edited by The Buzzard
Posted (edited)

Here is another way with less point selections and you only select midpoints.

You also supply the angle at the prompt.

 

 

Pseudocode: http://en.wikipedia.org/wiki/Pseudocode

The drawing has two (2) flange blocks.

1. Select the flange to be moved and rotated.

2. Supply the two (2) midpoints requested by the program.

3. Supply rotation angle in degrees at prompt.

4. Manipulate the flange to be moved to the flange to be aligned to.

 

This is RM2.lsp and uses RM2.dwg

 

[color=blue];;Moves and object in a parallel plane of another until it is perpendicular[/color]
[color=blue];;to it then rotates 1st object so that it lines up with it. Similar to [/color]
[color=blue];;align command.[/color]
[color=blue];;Written by Laison Albarado 11-09-2011 [/color]
;
(defun C:RM2 (/ AB AD DEG DPT ENT OS RAD SPT)             [color=blue];Declare local variables[/color]
 (setq OS    (getvar "osmode")                           [color=blue];Save User Object Snaps[/color]
       AB    (getvar "angbase")                          [color=blue];Save User angle base[/color]
       AD    (getvar "angdir"))                          [color=blue];Save User angle direction[/color]
 (or RM2:DEG (setq RM2:DEG 270))                         [color=blue];Set default angle[/color]
 (setvar "osmode" 2)                                     [color=blue];Set object snaps to midpoint[/color]
 (setvar "angbase" 0)                                    [color=blue];Set angle base[/color]
 (setvar "angdir"  0)                                    [color=blue];Set angle direction[/color]
 (setq ENT (ssget)                                       [color=blue];Select entity[/color]
       SPT (getpoint "\nSpecify source midpoint: ")      [color=blue];Get Source Midpoint[/color]
       DPT (getpoint "\nSpecify destination midpoint: "))[color=blue];Get Destination Midpoint[/color]
 (setq RM2:DEG
   (cond
     ((getint (strcat "\nSpecify rotation angle: <"(itoa RM2:DEG)">: ")))[color=blue];Get rotation angle[/color]
     (T RM2:DEG)))     
 (setq RAD (DTR RM2:DEG)                                 [color=#0000ff];Convert degrees to radians[/color]
       DEG (RTD RAD))                                    [color=blue];Convert radians to degrees[/color]
 (command "._move" ENT "" SPT DPT)                       [color=blue];Move Enitiy from SPT to DPT[/color]
 (command "._rotate" ENT "" DPT DEG)                     [color=blue];Rotate Enitity on basepoint DPT to degrees[/color]
 (setvar "osmode" OS)                                    [color=blue];Restore your Saved User Object Snaps[/color]
 (setvar "angbase" AB)                                   [color=blue];Restore your Saved User Angle Base[/color]
 (setvar "angdir" AD)                                    [color=blue];Restore your Saved User Angle Direction[/color]
 (princ)                                                 [color=blue];Exit quietly[/color]
)                                                         [color=blue];End defun[/color]
(princ)
(defun RTD (RAD)(* 180.0 (/ RAD pi))) [color=blue];Convert radians to degrees[/color]
(defun DTR (DEG)(* pi (/ DEG 180.0))) [color=#0000ff];Convert degrees to radians[/color]

RM2.dwg

Edited by The Buzzard
Posted
Here are 2 files, a before and after.

Did you test the two codes I posted?

Posted (edited)

Those are 3D.

You never mentioned anything about that.

From your original code you also would not have any indication this was for 3D.

This was a waste of time.

 

Some useful advise. When you start a thread in this forum, Be sure to be up front with your goal. Since you are new to coding and having some difficulties gettiing simple codes to to work, I suggest you put some time in and learn first at http://www.afralisp.net/index.php .

 

Also make sure your thread title mentions the topic clearly and post what you have done. The code on the first post looks like it was randomly put together. You want the help, Take the learning seriously.

 

If you think your going to just jump into 3D coding without mastering 2D coding, Then you have a long wait ahead of you. The good people here who help others to get through their coding issues are not going to write you a code just like that. You need to show some willingness on your part. If you need a code and do not want to bother learning how to do it for yourself, I suggest the search button in the upper right.

Edited by The Buzzard
Posted

Yes I did try them. I want to thank you for everything. I do not know of anyone that isn't doing 3D. From the descrisption in the lisp file I thought you knew it was for 3D purposes.

 

I do not want to take up your time.

 

;;Moves and object in a parallel plane of another until it is perpendicular
;;to it then rotates 1st object so that it lines up with it. Similar to 
;;align command

Posted (edited)
Yes I did try them. I want to thank you for everything. I do not know of anyone that isn't doing 3D. From the descrisption in the lisp file I thought you knew it was for 3D purposes.

 

I do not want to take up your time.

 

;;Moves and object in a parallel plane of another until it is perpendicular
;;to it then rotates 1st object so that it lines up with it. Similar to 
;;align command

 

 

Align can be used for either 2D or 3D. See if you can tweek some of the settings. I am not sure, But the UCS would also need to be manipulated also. Maybe you can post the two codes I gave you to a new thread and some with more 3D experience can get you through it. Looking at your comments in the drawing, You want to use ROTATE3D command and not just plain ROTATE. Since you are suppose to be experienced in 3D, Then why did you select just ROTATE command in your code if you were going to rotate the object on its axis. In addition to this I would assume that the distance you were trying to get was to offset the source object from the destination object by the distance you select in the same plane if I understand your drawing correctly.

 

I am just guessing here, But maybe something can be salvaged from all this. The question now is, Which code above can we use to save some extra work.

Edited by The Buzzard

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