Lisp routines no longer work Autocad 2016 and up

Lisp routines no longer work Autocad 2016 and up

Homecad2007
Enthusiast Enthusiast
1,805 Views
16 Replies
Message 1 of 17

Lisp routines no longer work Autocad 2016 and up

Homecad2007
Enthusiast
Enthusiast

Hi there

 

I am having troubles with this lisp routine that no longer seems to work in version 2016 and up.  2014 seems to work ok still

There are a few lisp routines in here so I apologize for that but the main ones that dont seem to work are Grading and Grading 1 and avgrade.

 

Any help would be great

Thanks

Tony

0 Likes
1,806 Views
16 Replies
Replies (16)
Message 2 of 17

CodeDing
Advisor
Advisor

@Homecad2007 ,

 

What does the command line history say when you try to run AVGRADE?

0 Likes
Message 3 of 17

Homecad2007
Enthusiast
Enthusiast

Actually that one is ok, but I want to add the TXTAT lisp routine scales down the attributed block where it needs to stay the same

0 Likes
Message 4 of 17

CodeDing
Advisor
Advisor

@Homecad2007 ,

 

This is the only line in TXTAT that would affect the scale of the block.. But it appears to be in the same format as in your other routines, so there would not be any apparent reason that scaling is changing..

(command "insert" "level" PAUSE "" "" TP1TANG TP1T )

Can you be more specific...

Is your block being scaled, and it shouldn't?

Or is your block not being scaled and you believe it should?

0 Likes
Message 5 of 17

Homecad2007
Enthusiast
Enthusiast

The block in 2014 stays the same size and no change.  In 2016 it becomes smaller...I agree not sure why or what is causing it to become smaller or it changed from one version to another

0 Likes
Message 6 of 17

pendean
Community Legend
Community Legend
Can you post a video or before/after screenshots showing how TXTAT changes the whole block's size as a whole as it converts text to attribute?

Or is your defined/active text style size just smaller than the existing text size and this is what is getting changed?
0 Likes
Message 7 of 17

CodeDing
Advisor
Advisor

In addition to what Pendean said, will you show us the properties of the blocks also? Most relevant is the scaling of the blocks..

 

Another thing that could be affecting the 'scale' of your blocks is your UNITS. Please be sure those are the same in both versions.

 

Best,

~DD

0 Likes
Message 8 of 17

Homecad2007
Enthusiast
Enthusiast

I tried creating a video but it was too large to send.

For the units, that seemed to do the trick, - How do I search and force units to be millimetres in they are something else

For the other routines such as Interp as shown in the image attached.  I try to select 1 attribute and then another and the error I receive is bad function.  Is it something with the attributes in 2016?

0 Likes
Message 9 of 17

CodeDing
Advisor
Advisor

@Homecad2007 ,

 

How do I search and force units to be millimetres


^^^ Use the INSUNITS variable and set it to 4 (or just make sure your template has it set to Millimeters).

 

(setvar 'INSUNITS 4)

 

 


For the other routines such as Interp as shown in the image attached.  I try to select 1 attribute and then another and the error I receive is bad function.

^^^ The "bad function" error is most likely because a parenthesis was incorrectly used OR because a predefined symbol was redefined to a real number. You can duplicate the error  like so:

 

(setq ang 45.9774)
(ang 3.14)

 

Try running this version of your function.. I only did 3 things:

- Declared local variables (Please start doing this, it is a necessary practice)

- Added spaces after function names / between parenthesis

- Moved 1 closing parenthesis [on your second (if (and (< INTP2X INTP1X) ..... statement]. It seemed incorrect.

 

Let me know if it works.

(defun c:interp ( / ostemp cnt tbdata intpt1 intpt1a intpt1x intpt2 intpt2a intpt2x newpt dist aa dist1 ang dist2 percent newelev elev dim txtht txtht1)
(SETVAR "ATTREQ" 1)
(SETVAR "ATTDIA" 0)
(setvar "cmdecho" 0)
(setvar "blipmode" 0)
(setq ostemp (getvar "osmode"))
(command "osnap" "node")
(setq cnt 0)

(prompt "\nPick first elevation : ")
(SETQ tbdata (entget (car (entsel))))
(setq INTPT1 (dxf 10 tbdata));GETS POINT 
(setq INTPT1A (entget (entnext (dxf -1 tbdata))))
(setq INTP1X (atof (dxf 1 INTPT1A)));GETS STRING

(prompt "\nPick second elevation : ")
(SETQ tbdata (entget (car (entsel))))
(setq INTPT2 (dxf 10 tbdata));GETS POINT 
(setq INTPT2A (entget (entnext (dxf -1 tbdata))))
(setq INTP2X (atof (dxf 1 INTPT2A)));GETS STRING

(SETVAR "OSMODE" 545)
(setq newpt (osnap (getpoint "\npick point for new elevation: ") "nea"))
(setvar "osmode" 0)
(setq dist (distance INTPT1 INTPT2))
(setq aa (angle INTPT1 INTPT2))
(setq dist1 (/ (distance INTPT1 INTPT2) 2))

(IF (< INTP1X INTP2X) (setq ang (ANGTOS (angle INTPT1 INTPT2))))
(IF (> INTP1X INTP2X) (setq ang (ANGTOS (angle INTPT1 INTPT2))))

(setq dist2 0)
(setq percent (/ (abs (- INTP1X INTP2X)) dist));slope percentage
(if (and (< INTP1X INTP2X) (/= dist2 nil)) (setq dist2 (distance INTPT1 newpt)) (setq newelev (* percent dist2)))
(if (and (< INTP2X INTP1X) (/= dist2 nil)) (setq dist2 (distance INTPT2 newpt)) (setq newelev (* percent dist2)))
(if (< INTP1X INTP2X) (setq elev (rtos(+ INTP1X newelev) 2 2)))
(if (< INTP2X INTP1X) (setq elev (rtos(+ INTP2X newelev) 2 2)))

(setq dim (getvar "dimscale"));;new
(Setq txtht (* dim 10));;new
(Setq txtht1 (* dim 10));;new

;;(command "insert" "level" newpt "" "" ang elev )
(command "insert" "level" newpt txtht "" ang elev )

(if (or (> (car INTPT1) (car INTPT2))
      (= (rtd aa) 270))
  (command "rotate" "last" "" newpt 180.0)
  );if
(setvar "cmdecho" 1)
(SETVAR "ATTDIA" 1)
(setvar "osmode" ostemp)
(princ)
)

Best,

~DD

 

0 Likes
Message 10 of 17

Homecad2007
Enthusiast
Enthusiast

Thank you for rewriting that for me and the tips however I still get the same error...bad function

0 Likes
Message 11 of 17

CodeDing
Advisor
Advisor

@Homecad2007 ,

 

Did another quick review of your lisp. This is the importance of declaring local variables and being sure not to overwrite predefined symbols. The highlighted line below redefines the angle symbol. So if at ANY time after running PIVOT, now every time the angle function is called, then it will give you the bad function error. Try using a different variable name in this function, instead of angle and let me know if that fixes it.

 

If it does not fix it, I would recommend going through the rest of your file checking for overwritten, predefined symbols.

(defun c:pivot()
;;(undobe)
(setq txtheight(getvar "txtht"))
(setq txtht 25)
(SETVAR "ATTDIA" 0)
(SETVAR "ATTREQ" 1)
(prompt "\nPick grade to pivot from")
(SETQ tbdata(entget (car (entsel))));low point selection
(setq PIVOTPT (dxf 10 tbdata));gets point of insertion of elevation attribute
(setq ang (dxf 50 TBDATA));gets angle of text
(setq tbdata (entget (entnext (dxf -1 tbdata))))
(setq PIVOTX (atof(dxf 1 tbdata)))

(setq angle (rtd ang));gets degrees of angle of text
.....

Best,

~DD

Message 12 of 17

john.uhden
Mentor
Mentor

That's why you will almost always find me naming my functions @Anonymous and @that, which allows me to name functions like @Anonymous and @angle.  Years ago I discovered that Autodesk  had established interoperability standards so that each of us who publish their work can have registered prefixes that won't duplicate others'.  But I don't think very many "publishers" abide by it.  Then again, that was in the time when local variables were not actually localized at all.  I used to always have to have a @Anonymous function to...

(setq this nil that nil etc nil)

on program exit, even if by cancelling.

Nowadays there can be many fewer conflicts if symbol names are localized.

John F. Uhden

0 Likes
Message 13 of 17

Sea-Haven
Mentor
Mentor

Good idea I use AH: after the master LM: in vlide it will give all local variables ( / ang back cut x y) so could take these and run replace in Notepad etc. Handy with some global variables that want to remember per session.

0 Likes
Message 14 of 17

Homecad2007
Enthusiast
Enthusiast

I have been able to fix the PIVOT lisp routine, thanks for some of the pointers however I am still having troubles with the INTERP and GRADE routines

 

for the INTERP routine I get the following error

pick point for new elevation: error: bad function: 45.9774

 

I have copied my latest lisp routine if anyone can see something else that might be wrong

 

Thanks

Tony

0 Likes
Message 15 of 17

Strydaris2492
Advocate
Advocate

Hi Tony, @Homecad2007 

 

I have an Interpolate LISP routine that will work in any situation.

In fact it is based off the knowledge I learned working at HomeCAD many years ago.

It is updated to work with text, Mtext or block attribute values.

It will also insert a block with the interpolated attribute value at the proper point and allow you to set where the attributed text sits.

 

Let me know if you are interested.

0 Likes
Message 16 of 17

ec-cad
Collaborator
Collaborator

I checked line by line. There are 24 items in that code that look suspecious.

In Notepad, search for <------

Change the code per suggestions in attached.

That may not be all of them.

Should get you closer to running.

 

ECCAD

Message 17 of 17

john.uhden
Mentor
Mentor

@ec-cad ,

That is very diligent work on your part!

John F. Uhden

0 Likes