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

0 Members and 1 Guest are viewing this topic.

FriendFromArea51

  • Swamp Rat
  • Posts: 675
  • Mars sucks!
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

  • Newt
  • Posts: 91
  • 30 + 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

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 8840
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.
“Common sense is not so common.” ~Voltaire

--> Donate to TheSwamp.org <--

CAB

  • Global Moderator
  • Seagull
  • Posts: 10237
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

  • Newt
  • Posts: 91
  • 30 + 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

FriendFromArea51

  • Swamp Rat
  • Posts: 675
  • Mars sucks!
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

  • Newt
  • Posts: 91
  • 30 + 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

  • Bull Frog
  • Posts: 425
Re: Is there software way to refactor autolisp routine?
« Reply #7 on: November 06, 2017, 04:36:27 pm »
Look into "TextCrawler".

FriendFromArea51

  • Swamp Rat
  • Posts: 675
  • Mars sucks!
Re: Is there software way to refactor autolisp routine?
« Reply #8 on: November 07, 2017, 03:36:25 am »

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 8840
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
“Common sense is not so common.” ~Voltaire

--> Donate to TheSwamp.org <--

FriendFromArea51

  • Swamp Rat
  • Posts: 675
  • Mars sucks!
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.