Lisp - Variables and Recursion

Greetings!

I have a question concerning the behaviour of variables in a Lisp-script. First of all let me explain the Situation:

I'm (still) working on a script to read all the information of the entities in a drawing (lines, polylines, circles, inserts and so on) such as the entity type, coordinates, and on, and on and on, and write thise into a file.
Now I've reached the point where I notice: I only get the first Level of subentities out of an Insert/Block. So if it contains other Inserts/Blocks I don't get their subentities!

What I plan to do:

I want to change the structure of my script.
The old strucure was about like this:

call get[entitytype]Data
[write the returned list  of Information of the corrosponding entity type to the file]
[call the next get function]

(all the way through till I worked through all entity types I want to extract)


Those functions scan through all entities in the drawing and get the information about the entities.
They work like this:


[code]
 (if (setq eset(ssget "X" (list (cons 0 "[corrosponding entity type here]"))))
   (progn
   [Loop through the set of entities doing the following]
   ->[gather information here]
   ->[write the information into a list]
   [end of the loop]
   )
[make sure the information list is returned]
)
[/code]

The new structure should work about like this:

[get all entities in the drawing and write them into a list (lets call it drawList)] (so I can call the new get-functions about like this: get[entitytype]Data(drawList))
[work through all call funtions]

Now Comes the critical Point: getBlockData()

I want to structure it about like this:

[get the information about the block (insertpoint, rotation and so on]
[write those into the returned information list]
[get a list of all subentities (lets call it subList)]
[call all the get[entitytype]Data(subList) function]
[write their infomation to the information list]
[last call getBlockData(subList)]
[write ist information to the information list]

Well, now I see, the recursive function getBlockData([insert entrance list here]) would allways use a variable named "subList", when it finds a Block/Insert in a Block/Insert in a Block/Insert (possibly an endless like of Blocks/Inserts in Blocks/Inserts).

Now my question is: Would a recursive call of getBlockData(subList) overwrite the variable "subList" or would it create a new /ist own instance of "subList"?
I'm afraid that could be the fact and I would loose a lot of information.


Another issue that came to my mind: I know how to get a list of all subentities from a Block/Insert (thanks again to Konstantin Sakellaris and Roy Klein Gebbinck) and  I understand (I think) how ssget works what I'd need (and don't understand how I get it) would be the list behind the name I get from "(ssget "X")" so I can store it in the variable drawList.

I'm as allways thankfull for every help I get and will explain possibly missunderstandable explenations. (Since english actually isn't my mothertongue I can imagine I write pretty missunderstandable sometimes)

ALLSO: Sorry for the constand Block/Insert. In german  ist a bit tricky for me to tell what what is called and what it actually is internal.

Comments

  • Steven, you are jumping in at the deep end. You are working on a big project but are struggling with the basics.

    For example:
    Difference between local an global variables:
    http://www.afralisp.net/autolisp/tutorials/the-define-function.php

    My advice would be to start with the basics and then sink your teeth into some smaller projects before doing this one.

    To get the list 'behind' a selection set:
    [code](defun Pickset_To_EnameList (ss / i ret)
      (if ss
        (repeat (setq i (sslength ss))
          (setq ret (cons (ssname ss (setq i (1- i))) ret))
        )
      )
    )[/code]
  • I would LOVE to start simple but this is my actual task at work at the Moment. And none of us at the office really knows much about how Lisp works. we just badly need it to improve the speed of an interface.
  • You might want to try posting at www.theswamp.org [requires free sign-up] or at www.cadtutor.net.  Both sites have forums specifically for lisp.  You may also find lisp functions that will help at www.lee-mac.com.

    This might be something that it would be best to hire a contract programmer for.  I agree with Roy that this is a bigger project than I'd recommend as a first project.  Considering the learning curve for lisp it could take weeks for a new programmer to get this working.  A good contract programmer would need far less time.

     
  • @ Steven: What do you mean by "improve the speed of an interface"?
  • @Martin
    Thanks for the tip

    @Roy
    Well the company I work for sells a program, that includes 2D and 3D room planning. Now see, if you have a .dwg file that contains the architectural plan of a room or even the entire floor of an office building and want to furnish it with 3D Office (Google it) you don't have to redraw the floor with the floor manager you can just import a .dwg file. At the moment this import works via the com interface, wich can take a lot of time. It works a lot faster to read the needed information directly from a file generated by a Lisp script.
    Sorry if I messed up some  specific expressions, I'm still a Trainee.

  • Steven,

    have you investigated exporting from BricsCAD .dwg to .dxf format using either _DXFOUT, or _EXPORT? I would wager that you will find your 3D Office (googled looks like there are a number of apps with this name) can import and export in .dxf. i.e explorer other file formats that are faster than using .dwg. My guess if they're using COM is that they are using a 3rd party utility to do the conversion for them.

    You could also investigate the applications area of the Bricsys site for import/export options provided by 3rd parties. Maybe .3DS would be better
    http://www.bricsys.com/common/applications/applicationlist.jsp?estore.ApplicationCategory=13

    If 3D office can import Images/PDF then perhaps printing to an Image/PDF might provide a suitable workaround.

    You might also like to look at BricsCAD options for rendering and walkthru's. Artisan comes to mind here. i.e. do it the other way around, export from 3D Office to BricsCAD.
    http://www.bricsys.com/common/applications/applicationlist.jsp?estore.ApplicationCategory=10

    BTW, keep going with LISP. For a beginner I'm impressed with how far you've got with what is a difficult task. If you continue along this path maybe this post on the swamp is of help
    http://www.theswamp.org/index.php?topic=31145

    Regards,

    Jason Bourhill

    CAD Concepts


  • Thanks for the advise Jason, honestly I've llmost reached the Point, where i can  say: Good, now the rest is just cleaning up.
    The last "major" obsstacles now are basically some Points about understanding what I actually did. I did way too much try and error and SHOULD be able to do the rest on my own (maybe).
    I know how to read Information that i need from a list of entities and i know how to get the list of subentities from a block. SO yes basically i need  to clean out my mind of false syntax and write the rest of the code.


    Again thanks to everyone!
This discussion has been closed.