Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Stuck on an AutoLISP program

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
donm
857 Views, 7 Replies

Stuck on an AutoLISP program

First of all, I am a complete novice at AutoLISP, and trying to teach myself the code through a combination of old books (way out of date) and online tutorials. That said, I took an AutoLISP program that draws beams from external data utilizing a dialog box from Kenny Ramage's web site and retooled it to draw the plan views of ASME pipe flanges.  I first wrote a version that would work with user defined data while running the program to make sure I had that code correctly. This program, entitled flgplan.lsp, runs perfectly.  However, my program utilizing external data, entitled flgface.lsp hangs up at the last command line, the "array" command, and prompts for input for the rest of the command.  I'm completely stumped as to why this is happening as all those command line codes are written indentically to the shorter program that works perfectly.  I'm tempted to think that the variable NH is somehow not loading properly from the external data file, since that is the first prompt requested, but that doesn't make sense since the command line just previous the the array command uses this same variable and seems to work correctly.  So I'm hoping one of you expert coders can show me where I've gone wrong here and why things are hanging up.

 

I can only attach 3 files, so here is the simple program:

(defun C:flgplan (/)    ;function defined

  
  (setq OLDECHO (getvar "CMDECHO")  ;store system variables
        OLDBLIP (getvar "BLIPMODE")
 OLDSNAP (getvar "OSMODE")
  );setq
  (setvar "CMDECHO" 0)
  (setvar "BLIPMODE" 0)
 
;;;*This routine draws the flg face.


      
      (setq OLDSNAP (getvar "OSMODE"))
      (setq CF (getpoint "\n Enter center of of flange: "))
      (setq FLGOD (getdist "\n Flg OD: "))
      (setq RFOD (getdist "\n Raised face OD: "))
      (setq FLGID (getdist "\n Flg ID: "))
      (setq BC (getdist "\n Bolt circle: "))
      (setq NH (getint "\n Number of holes: "))
      (setq DH (getdist "\n Diameter of bolt holes: "))
      (setq CFH (polar CF 0.0 (/ BC 2)))
      (setvar "OSMODE" 0)
      (command ".circle" CF (/ FLGOD 2))
      (command ".circle" CF (/ RFOD 2))
      (command ".circle" CF (/ FLGID 2))
      (command ".circle" CFH (/ DH 2))
      (command ".rotate" (entlast) "" CF (/ 360.0 NH 2))
      (command ".array" (entlast) "" "p" CF NH "360" "n")  
     )  
  
(setvar "OSMODE" OLDSNAP)
(setvar "BLIPMODE" OLDBLIP)
(setvar "CMDECHO" OLDECHO)
  (princ)
);defun flgplan

 

Attached is the program hanging up, flgface.lsp

the dialog box code, flgface.dcl

I was unable to attach the data file, so here it is:

**FLANGE FACE DATA
**-----------------------
**FLGOD X RFOD X FLGID X BC X NH X DH
**-----------------------
*1/2
3.5,1.375,0.88,2.375,4,0.625
*3/4
3.875,1.6875,1.09,2.75,4,0.625
*1
4.25,2.0,1.36,3.125,4,0.625
*1-1/4
4.625,2.5,1.7,3.5,4,0.625
*1-1/2
5.0,2.875,1.95,3.875,4,0.625
*2
6.0,3.625,2.44,4.75,4,0.75
*2-1/2
7.0,4.125,2.94,5.5,4,0.75
*3
7.5,5.0,3.57,6.0,4,0.75
*3-1/2
8.5,5.5,4.07,7.0,8,0.75
*4
9.0,6.1875,4.57,7.5,8,0.75
*5
10.0,7.3125,5.66,8.5,8,0.875
*6
11.0,8.5,6.72,9.5,8,0.875
**-------------------------

 

Thanks for your help,

Don in Portland

7 REPLIES 7
Message 2 of 8
hgasty1001
in reply to: donm

Hi,

 

Change "p" for "po" if polar, or "pa" if path

 

Gaston Nunez

Message 3 of 8
donm
in reply to: hgasty1001

Well, no, that made no difference, as I anticipated.  The program that is included in my post works just fine.  The program that is attached--a much longer program the utilizes a dialog box (the dcl code program attached)--and data from a data file, that I included in the post itself (because this forum would not allow an attachment with a .dat extension), is the one that hangs up.  What has me stumped is that the command line code parts of that longer program are written *exactly* identical to the shorter program that works.  And it hangs up in that "array" command past the point of both the polar, and the center point selections part of the command.  It seems to go haywire at the "number of entities" part of the command and prompts for that.  If I then manually enter that and the subsequent selections ("angle to fill" & "rotate arrayed objects?") the program completes the drawing.  But with the shorter flgplan.lsp program the array command works from the code written without interruption or further prompts.  That's what has me so flummoxed: the command code is identical between the two programs.  And I know the variable is loaded from the data file because that same variable--NH--is used successfully in the previous command code line, the "rotate" command.

Message 4 of 8
hgasty1001
in reply to: donm

Hi,

 

Using this line : (command ".array" (entlast) "" "po" CF NH "360" "") the routine works.

 

Gaston Nunez

Message 5 of 8
donm
in reply to: hgasty1001

Sorry, Gaston, I just tried it and it made no difference.  The flgface.lsp program still hangs up on the "array" command line and prompts for "number of entities".  I'm not sure if you are trying this on the simpler program written out in the post itself, the flgplan.lsp.  As I've said, that one works just fine as written.  The flgface.lsp, however is attached to the post, along with the flgface.dcl.  To test this program out you must have the flgface.lsp file, the flgface.dcl file, and you must creat a flgface.dat file from the data that I included at the end of the post (the forum would not allow me to attach this file as .dat extensions are prohibited for attachment).  And you must have all three files in the same directory with a support path to that directory in your AutoCAD file settings.

 

The whole purpose for this longer program is to be able to draw standard flange faces from data files of ANSI standard flanges, i.e. series A 150#, 300#, etc. and Series B 150#, 300#, etc.  I actually have all of these in dynamic blocks with visibility states, but these tend to be quite large blocks and slow down drawing save times.  If I can get this program to work such that it will draw a flange face from a list it will both streamline the process and keep extraneous unneeded data from accumulating in the drawing and slowing down the save time, or a need to purge all of that stuff out.

 

Thanks,

Don

Message 6 of 8
hgasty1001
in reply to: donm

Hi,

 

It seems that the problem it's NH, try fixing it. The array needs an integer as the number of items, son change NH by (fix NH)

I changed array by arraypolar in this way: (command "arraypolar" (entlast) "" CF "i" (fix NH) "a" "" "") and it works now.

 

Gaston Nunez

 

Message 7 of 8
donm
in reply to: hgasty1001

Yes, adding the "fix" to the NH variable did the trick.  What's odd about this, however, is this occurred to me when I saw the "requires and integer" message in the prompt when the program would hang up, so I went back to the data file and removed zeroes and decimal points from the numbers in the NH column.  But I guess since the variables are all loaded by the MAPCAR command, without specific instructions to set that variable as integer it must default to real. 

 

Thanks so much for your help, Gaston.  Much appreciated.

Message 8 of 8
devitg
in reply to: donm

Any other time you need to Upload files, ZIP it , or RAR it

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost