Author Topic: Dictionary project  (Read 11982 times)

0 Members and 1 Guest are viewing this topic.

Arch_Eric

  • Guest
Dictionary project
« on: May 28, 2008, 11:38:01 AM »
Before I started my next project, I wanted to get the experts opinion on it.

- Create a dictionary with keys:
  * Parent object - text entity to store number total
  * Calculation type - either area or sum
  * Child objects - polyline entities to calculate area or text entities to calculate sum
- Create a rector for regen and/or qsave/save to read the dictionary and do calculations
  * Alert - missing entities
- Create function to manage dictionary

I'm trying to make my square footage calculations automatic. I already have the code to calculate areas and add text entities. The reactor part I'm useless on, I'll have to do some research on reactors. And I've been trying to work with ssget to select entities by DXF code 5 (handle) but I can't seem to get it to work. I think I read somewhere that ssget doesn't work with code 5, which doesn't make sense to me. Is there a way to translate an entity handle to an ename?

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Dictionary project
« Reply #1 on: May 28, 2008, 11:41:47 AM »
You can use the built in function 'handent' to get the ename from the handle.

You can use mtext/attributes and fields to hold the value of square footages of plines.

I have put up a reactor here to area.
[ http://www.theswamp.org/index.php?topic=8710.0 ]
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Arch_Eric

  • Guest
Re: Dictionary project
« Reply #2 on: May 28, 2008, 12:07:49 PM »
Doh! :ugly: How the hell did I miss handent...thanks for pointing that out. And thanks for the link  :-)

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: Dictionary project
« Reply #3 on: May 28, 2008, 12:23:05 PM »
I'm confused.  What's the dictionary for?
James Buzbee
Windows 8

Arch_Eric

  • Guest
Re: Dictionary project
« Reply #4 on: May 28, 2008, 12:30:25 PM »
I was thinking of storing my handles and info in there, because I'll have more than one polyline for some area calculations, and 3+ handles to calculate the sums of the areas.

daron

  • Guest
Re: Dictionary project
« Reply #5 on: May 28, 2008, 02:26:50 PM »
When you get that complete, I'd love to "borrow" it from ya. I've got something similar to do.

Arch_Eric

  • Guest
Re: Dictionary project
« Reply #6 on: May 28, 2008, 04:05:33 PM »
I'm travelling down the dark path with this one.

I'm using... LData.  :|

daron

  • Guest
Re: Dictionary project
« Reply #7 on: May 28, 2008, 04:31:39 PM »
No biggie. I'll still take it.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Dictionary project
« Reply #8 on: May 28, 2008, 04:50:50 PM »
I'm travelling down the dark path with this one.

I'm using... LData.  :|
From all the posts I have seen, LData is not the desired road.  Maybe we can give you some better directions to the promised land.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

daron

  • Guest
Re: Dictionary project
« Reply #9 on: May 28, 2008, 04:57:01 PM »
We have, but the problem is that Ldata is too easy to use. What it should be is a wrapper (front-end) for xdata.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Dictionary project
« Reply #10 on: May 28, 2008, 05:03:54 PM »
We have, but the problem is that Ldata is too easy to use. What it should be is a wrapper (front-end) for xdata.
XData
Code: [Select]
    (defun MySetXData (Obj CodeList DataList / )
        ; Sets XData to an object.  Must number in code list must be 1001
       
        (vla-SetXData Obj
            (vlax-make-variant
                (vlax-safearray-fill
                    (vlax-make-safearray
                        vlax-vbInteger
                        (cons 0 (1- (length CodeList)))
                    )
                    CodeList
                )
            )
            (vlax-make-variant
                (vlax-safearray-fill
                    (vlax-make-safearray
                        vlax-vbVariant
                        (cons 0 (1- (length Datalist)))
                    )
                    DataList
                )
            )
        )
    )
;-----------------------------------------------------------------------------
    (defun MyGetXData (Obj DataName / CodeType DataType)
        ; Retrive XData for an object
       
        (vla-GetXData
            Obj
            (if DataName
                DataName
                ""
            )
            'CodeType
            'DataType
        )
        (if (and CodeType DataType)
            (mapcar
                '(lambda (a b)
                    (cons a (variant-value b))
                )
                (safearray-value CodeType)
                (safearray-value DataType)
            )
        )
    )
XRecords
Code: [Select]
    (defun MySetXRec (Obj CodeList DataList / )
        ; Sets XRecordData. Dxf numbers between 1-369, except 5, 100, 105.
        ; See help for types and numbers to use.
       
        (vla-SetXRecordData Obj
            (vlax-make-variant
                (vlax-safearray-fill
                    (vlax-make-safearray
                        vlax-vbInteger
                        (cons 0 (1- (length CodeList)))
                    )
                    CodeList
                )
            )
            (vlax-make-variant
                (vlax-safearray-fill
                    (vlax-make-safearray
                        vlax-vbVariant
                        (cons 0 (1- (length Datalist)))
                    )
                    DataList
                )
            )
        )
    )
;-----------------------------------------------------------------------------
    (defun MyGetXRec (Obj / CodeType DataType)
        ; Retrive XRecordData for an object
       
        (vla-GetXRecordData
            Obj
            'CodeType
            'DataType
        )
        (if (and CodeType DataType)
            (mapcar
                '(lambda (a b)
                    (cons a (variant-value b))
                )
                (safearray-value CodeType)
                (safearray-value DataType)
            )
        )
    )
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Arch_Eric

  • Guest
Re: Dictionary project
« Reply #11 on: May 28, 2008, 05:59:43 PM »
The only problems I could find on the net about LData was when moving a drawing from R14 to 2000 it would corrupt the drawing or something.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Dictionary project
« Reply #12 on: May 28, 2008, 07:18:57 PM »
The only problems I could find on the net about LData was when moving a drawing from R14 to 2000 it would corrupt the drawing or something.

[ http://discussion.autodesk.com/thread.jspa?messageID=1213664 ]
[ http://discussion.autodesk.com/thread.jspa?messageID=2045434 ]
[ http://discussion.autodesk.com/thread.jspa?messageID=4951203 ]

These are just opinions by people I have come to respect in the programming scheme of things, so I stay away.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

daron

  • Guest
Re: Dictionary project
« Reply #13 on: May 28, 2008, 10:55:08 PM »
Thanks Tim, I'll have to borrow those.

Arch_Eric

  • Guest
Re: Dictionary project
« Reply #14 on: May 28, 2008, 11:31:40 PM »
I'm not saying those guys aren't experts, but reading those posts, they say exactly the same thing. Someone asks about LData, somebody says avoid it like the plague. The person asks why and they say because LData didn't transfer from R14 to 2000 and because it's not accessible via VBA. I understand that and all, but that was 9 years ago, and while I'm not (yet) playing with VBA, I don't see why it should be avoided altogether. I'm fairly new to AutoLISP, and in no way want to piss off anybody that will help me learn. I'm just asking questions.  :angel:

I've already got my stuff working except for reactors, but I'm not really in a hurry for that. I'm just enjoying the fact it works.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Dictionary project
« Reply #15 on: May 29, 2008, 11:03:05 AM »
You wouldn't make me mad by using LData, but I wouldn't be able to help since I have never used it since I read those posts.  My thinking was better safe than sorry, and since I can code it in another way without any rick of problems, then that is the way I would want to go.  To each their own, and I hope you have no problems with LData.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Arch_Eric

  • Guest
Re: Dictionary project
« Reply #16 on: May 29, 2008, 11:15:07 AM »
Here is my working code, Daron. Run DAREA and select ParentAdd. Click your text object to hold the total, choose whether it's a sum (sum of other text objects) or area (area of polylines) object, then select each child object. ParentDelete deletes all links to the parent object, ChildDelete deletes a single link. ChildAdd adds a single link to an existing parent. Cleanup checks for deleted objects and removes their links.

DISCLAIMER: This code uses LDATA functions and may or may not cause problems. Use at your own risk. See above posts.

daron

  • Guest
Re: Dictionary project
« Reply #17 on: May 29, 2008, 11:56:30 AM »
Thanks.

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: Dictionary project
« Reply #18 on: May 29, 2008, 01:48:07 PM »
LData:

Luis E. and I did extensive testing of Ldata back in the day.  Some of the more heinous side effects were corruption of collections, and vertical application collections (specifically ADT).  What was apparently happening, if say a block had ldata attached to it, there was a strong possibility for the Blocks collection to become corrupted.  It was severe in the Vertical application collections (ADT WallStyles, etc.) because these "collections" are defined in AEC_ dictionaries. 

I don't know the how, I don't know if it's been fixed, but I had to reconstitute a major part of an architectural project I was working on due to LData.  I'll never use it again.
James Buzbee
Windows 8

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Dictionary project
« Reply #19 on: May 29, 2008, 02:00:53 PM »
LData:

Luis E. and I did extensive testing of Ldata back in the day.  Some of the more heinous side effects were corruption of collections, and vertical application collections (specifically ADT).  What was apparently happening, if say a block had ldata attached to it, there was a strong possibility for the Blocks collection to become corrupted.  It was severe in the Vertical application collections (ADT WallStyles, etc.) because these "collections" are defined in AEC_ dictionaries. 

I don't know the how, I don't know if it's been fixed, but I had to reconstitute a major part of an architectural project I was working on due to LData.  I'll never use it again.
Thanks for sharing you experience James.  Another reason I'm glad I never tried ldata.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

hermanm

  • Guest
Re: Dictionary project
« Reply #20 on: May 29, 2008, 03:20:40 PM »
I've only used ldata to store drawing specific variables, in a dictionary owned by named object dictionary, and only in "recent" versions of AutoCAD.

In that context, I have experienced no difficulties with ldata.

As regards access to ldata from other programming environments,

http://discussion.autodesk.com/thread.jspa?messageID=5896693

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Dictionary project
« Reply #21 on: May 29, 2008, 04:53:49 PM »
I've only used ldata to store drawing specific variables, in a dictionary owned by named object dictionary, and only in "recent" versions of AutoCAD.

In that context, I have experienced no difficulties with ldata.

As regards access to ldata from other programming environments,

http://discussion.autodesk.com/thread.jspa?messageID=5896693
Thanks for sharing your good experience, as we need both sides.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Arch_Eric

  • Guest
Re: Dictionary project
« Reply #22 on: May 30, 2008, 02:21:48 PM »
I found a library of functions (vlax-ldata.lsp) to replace LData functions that function exactly the same way, except they use XRecords. So there shouldn't be any problems with it. So I replaced my function calls and everything works. Now I'm working on my reactor, and I've run into a problem that has stumped me.

When I make a change to my polyline, it calls the recalc function and all my totals update. If I undo the change, it errors out in the recalc function, even though it's calling the same function. Its in the inside foreach loop that gets the area of the polylines. When it calls the vlax-curve-getarea function, it comes back saying my variable is empty. I check the list object that foreach calls and it's got data. Doesn't make sense...

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Dictionary project
« Reply #23 on: May 30, 2008, 02:52:23 PM »
Eric,
I would like to mention a few things.
 (vl-load-com) need only be executed once per DWG session so place it in the lisp file so that
 when the lisp is loaded it will get it done once.
 
 (setvar "cmdecho" 0) only comes into play when you use a COMMAND or vl-cmdf so there is no need for it.
 
 One last thing. The While loop can use a progn so your code can be modified to this.
Code: [Select]
(defun c:darea (/ darea-option)
  (setvar "cmdecho" 0)
  (princ "\n*** DYNAMIC AREA ***")
  (while
    (progn
      (initget "PAdd PDelete CAdd CDelete List CLeanup Recalc")
      (setq darea-option
             (getkword
               "\n[ParentAdd/ParentDelete/ChildAdd/ChildDelete/List/CLeanup/Recalc] <Exit>: ")))
     (cond
       ((= darea-option "PAdd") (ld-addparent))
       ((= darea-option "PDelete") (ld-delparent))
       ((= darea-option "CAdd") (ld-addchild))
       ((= darea-option "CDelete") (ld-delchild))
       ((= darea-option "List") (ld-listchildren))
       ((= darea-option "CLeanup") (ld-cleanup))
       ((= darea-option "Recalc") (ld-recalc nil nil nil))
     )
  )
  (princ)
)
« Last Edit: May 30, 2008, 03:24:12 PM by CAB »
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.

daron

  • Guest
Re: Dictionary project
« Reply #24 on: May 30, 2008, 03:10:58 PM »
Even if you do continue to use it, save the users initial settings to a variable so you can return it to them later. Yes, you only have a 50/50 chance, but what if the user likes cmdecho set to 0. Let the computer decide what to set it back to. Also with the idea of reactors and I'm not sure if this will be an issue here, but (vla-regen (vla-get-activedocument (vlax-get-acad-object)) acAllViewports) will keep you away from using command in this case. Just be sure and set your vla objects to a variable for later clearing.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Dictionary project
« Reply #25 on: May 30, 2008, 03:27:05 PM »
Eric,
  You can also replace (command "regen") with
  (vla-regen (vla-get-activedocument (vlax-get-acad-object)) acactiveviewport)
  or as Daron suggested
  (vla-regen (vla-get-activedocument (vlax-get-acad-object)) acAllViewports)

Daron beat me to it. :)

PS looks like you have the regen in each sub function so no need to include it in the main routine.
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.

Arch_Eric

  • Guest
Re: Dictionary project
« Reply #26 on: May 30, 2008, 04:12:00 PM »
Thanks for the pointers guys. I was starting to look for a replacement for calling Regen with command.