Jump to content

Complex Code Clarification Requested


Recommended Posts

Posted

I have been working on a process for a client which is working great. Most of the code I came up with through trial and error, asking questions of this group, and some dumb luck. All in all it works and we're about ready to move on to another phase. There is some of the code which I fully understand and other parts I only partly understand. Here is one of those snippets that I would like to ask the experts if you could, in laymen's terms, give some more detailed explanation as to what is going on.

 

(setq acadobject (vlax-get-Acad-Object))
 (setq activedocument (vla-get-activedocument acadobject))
 (setq LayerTable (vla-get-layers activedocument))

 

I see how this is assigning certain variables on the left. And then there are these very scary looking things on the right. If I understand this right and as I have seen from some other examples, the variable names on the left are not fixed and each user could pick and choose the ones they want. Obviously, these names were chosen because they closely match the objects on the right. The objects on the right are rigid and cannot be messed with. I seem to have figured out this is where a lot of the confusion I had in the beginning was seeing one person's block of code and then comparing similar if not the same type of code to another person's. And this is where beginners get thrown off track. I guess I should add that this seems like an awful lot of work to go through just to get the variable LayerTable set so you can do some more work with it on down in the code. But I do understand this is a stepped process and why. I just would like to hear some more details on the other items on the right side.

 

It's a situation now of I have this working but I don't really understand what it's doing. I have even more complex code in the VBA portion of this project which I will post a similar type of question in the other area of the forum.

Posted

I am no expert but when using VBA Vl .net etc you have to "open" the autocad database to do something with it thats what the first couple of lines are doing. The 3rd line is retrieving something from the "open" database.

 

here is an example of opening the civil 3d database taking into account the Autocad Version

(if ((lambda (vrsn)
       (cond
        ((vl-string-search "R17.2" vrsn) (setq appstr "6.0")) ;09
        ((vl-string-search "R18.0" vrsn) (setq appstr "7.0")) ;10
        ((vl-string-search "R18.1" vrsn) (setq appstr "8.0")) ;11
       ((alert "This version of C3D not supported!"))
       )
      )
      (vlax-product-key)
     )                         ; end if condition progn is true
     (progn
       (cond (*AeccDoc*)
         ((setq *AeccDoc*
           (vlax-get
             (cond (*AeccApp*)
               ((setq *AeccApp*
                 (vla-getinterfaceobject
                    (cond (*Acad*)
                    ((setq *Acad* (vlax-get-acad-object)))
                    )
                    (strcat "AeccXUiLand.AeccApplication." appstr)
                 )
                )
               )
             )
             'ActiveDocument
           )
          )
         )
       ) ; end main cond
     ) ; end progn
) ; end if vsrn

 

Next you write code to do something

 

To make life easier create a defun that contains this code autoload it and just call it at start I have done this for multiple civ3d routines also when 2013 comes only need to add 1 line to 1 program.

 

Ps any one out there appstr & versn No for 2013

Posted

Maybe this explanation will help:

 

http://www.cadtutor.net/forum/showthread.php?53374-xref-clip-boundry&p=361940&viewfull=1#post361940

Posted

Could this

 

(setq acadobject (vlax-get-Acad-Object))
(setq activedocument (vla-get-activedocument acadobject))
(setq LayerTable (vla-get-layers activedocument))

 

also have been written like this:

 

(setq LayerTable (vla-get-layers (vla-get-activedocument (vlax-get-Acad-Object))))

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...