Author Topic: Is there software way to refactor autolisp routine?  (Read 2075 times)

0 Members and 1 Guest are viewing this topic.

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
Is there software way to refactor autolisp routine?
« on: November 03, 2017, 02:44:25 PM »
Is there a way to rename lisp variables / functions through entire files easily?

BIGAL

  • Swamp Rat
  • Posts: 1409
  • 40 + years of using Autocad
Re: Is there software way to refactor autolisp routine?
« Reply #1 on: November 03, 2017, 06:49:07 PM »
Its called Replace  :2funny:

You could write a lisp that looks for "setq" in a line, then "setq variable" and change the variable name, only problem is code with (setq a 1 b 2) when using wcmatch it gives a starting point so step across the string till the next space after the variable. change the variable name and rewrite the line. It is doable needs a lambda function for the replace bit. Need to think about it a bit more.

In my case I want to add AH- to variable names to make them individual its a bit easier than changing the whole name. Oh yeah need to check the starting (defun statement also ( / pt1 pt2 ) etc



« Last Edit: November 03, 2017, 06:52:20 PM by BIGAL »
A man who never made a mistake never made anything

JohnK

  • Administrator
  • Seagull
  • Posts: 10625
Re: Is there software way to refactor autolisp routine?
« Reply #2 on: November 03, 2017, 08:11:10 PM »
Use a good text editor. Any good editor should support regex.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Is there software way to refactor autolisp routine?
« Reply #3 on: November 03, 2017, 08:16:39 PM »
I think it can be a bit tricky just doing a replace across multiple list files.
Some variables share letters that may be replaced.
Setq can have many variables  (setq a 2 b5 c 8)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

BIGAL

  • Swamp Rat
  • Posts: 1409
  • 40 + years of using Autocad
Re: Is there software way to refactor autolisp routine?
« Reply #4 on: November 03, 2017, 10:17:04 PM »
Like you Cab as you run it would ask old variable new variable name making a list which will grow its a bit of a task. Using a macro in word may be easier looking for a number of predefined variable names. I use stuff like pt pt1 all the time but the names could be a bit trickier. layname layername lname etc all the same depending on what I feel like when typing. It may need a 1st pass get all variable names make a list with pairs old new then second pass actually change them. Obviously making a new file.

« Last Edit: November 03, 2017, 10:23:05 PM by BIGAL »
A man who never made a mistake never made anything

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
Re: Is there software way to refactor autolisp routine?
« Reply #5 on: November 03, 2017, 11:22:38 PM »
Thanks guys, looks like I'll need to just grind through.  Appreciate it!

BIGAL

  • Swamp Rat
  • Posts: 1409
  • 40 + years of using Autocad
Re: Is there software way to refactor autolisp routine?
« Reply #6 on: November 04, 2017, 07:58:56 PM »
Yeah no quick solution just me though I stay away from *acad* as variable names always get worried about using characters like *.

I know that commercially I would add a prefix to all my defuns.

Making c:now can be a risk if someone else uses now, so usually make my defun naming a bit obscure c:ahfindints
A man who never made a mistake never made anything

Biscuits

  • Swamp Rat
  • Posts: 502
Re: Is there software way to refactor autolisp routine?
« Reply #7 on: November 06, 2017, 04:36:27 PM »
Look into "TextCrawler".

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
Re: Is there software way to refactor autolisp routine?
« Reply #8 on: November 07, 2017, 03:36:25 AM »

JohnK

  • Administrator
  • Seagull
  • Posts: 10625
Re: Is there software way to refactor autolisp routine?
« Reply #9 on: November 07, 2017, 03:05:11 PM »
Any good editor should allow you to use regex.

Also, you could also use the preprocessor I built (it's called LiFP) to do simple search and replace.
https://www.theswamp.org/index.php?topic=37700.0
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
Re: Is there software way to refactor autolisp routine?
« Reply #10 on: November 13, 2017, 02:12:45 AM »
Any good editor should allow you to use regex.

Also, you could also use the preprocessor I built (it's called LiFP) to do simple search and replace.
https://www.theswamp.org/index.php?topic=37700.0

Thanks seven...impressive as always.