Author Topic: Custom AutoCAD Fields  (Read 7205 times)

0 Members and 1 Guest are viewing this topic.

jtoverka

  • Newt
  • Posts: 127
Custom AutoCAD Fields
« on: September 25, 2019, 01:05:40 PM »
All,

I use AutoCAD Electrical 2018. I like fields as it reduces manual work and errors. I use fields for the ladder blocks to use the project code. That way, if I update the project code, everything that uses that value will be updated (after refresh).

Here is the string that goes into the text entity: "%<\AcVar CustomDP.Project Code \f "%tc1">%"

One thing to note is the "CustomDP.Project Code"

This value is stored in a block called WD_M in the IEC_PROJ attribute. If I edit this block with a new Project code, the drawing does not get updated upon refresh. However, If I open the drawing properties dialog box it will show the updated project code. When I hit okay (even though I didn't "update" anything) and refresh, the drawing gets updated.

Using the drawing properties dialog box is actually the "proper" way of updating information in the WD_M block. This part is important for my question.

My question is this:
How do I create my own custom variables to use in the AutoCAD fields? This isn't entirely being referenced from another object (WD_M block), not directly anyways. That information is sent somewhere where this custom variable is referencing from. If I delete the WD_M block, the value is still the same code.


Atook

  • Swamp Rat
  • Posts: 1027
  • AKA Tim
Re: Custom AutoCAD Fields
« Reply #1 on: September 25, 2019, 04:31:37 PM »
If you purge the block, does the value persist?

If not, you may have to update the block definition.

jtoverka

  • Newt
  • Posts: 127
Re: Custom AutoCAD Fields
« Reply #2 on: September 25, 2019, 07:57:12 PM »
If you purge the block, does the value persist?

Purging the WD_M block does not change the field value.

I am interested in how AutoCAD Electrical gets this value, it has to be stored in a dictionary or something. I just want to be able to create custom values to use in fields. If I can store a value in a dictionary to have it show up as a field option in the dialog box then that would be great.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8658
  • AKA Daniel
Re: Custom AutoCAD Fields
« Reply #3 on: September 25, 2019, 11:15:25 PM »
Hi,
Does the UPDATEFIELD command work?
From an API perspective, you can also update field(s) directly.

You can create your own custom field, there’s an example in one of the ARX SDKs, caveat its C++, so you'll need to translate it to .net.
Its not trivial to do, but not crazy hard

jtoverka

  • Newt
  • Posts: 127
Re: Custom AutoCAD Fields
« Reply #4 on: September 26, 2019, 08:48:35 AM »
Hi,
Does the UPDATEFIELD command work?
From an API perspective, you can also update field(s) directly.

You can create your own custom field, there’s an example in one of the ARX SDKs, caveat its C++, so you'll need to translate it to .net.
Its not trivial to do, but not crazy hard


Once I update the WD_M block attribute using properties palette or the enhanced attribute editor dialog box, it does not update the project code stored elsewhere in the drawing. I tried using updateField and it "updates" the block using the old project code. It is only when I open the drawing properties dialog box does it actually update. That dialog box has code stored in it that updates something in the drawing that is tied to the fields.

I just found these
https://knowledge.autodesk.com/support/autocad/learn-explore/caas/CloudHelp/cloudhelp/2015/ENU/AutoCAD-Core/files/GUID-8FCDDD74-0FDC-4189-8407-9EC9D7D482C5-htm.html
https://forums.autodesk.com/t5/net/set-a-custom-drawing-property/td-p/6893092

This answers my question.

jtoverka

  • Newt
  • Posts: 127
Re: Custom AutoCAD Fields
« Reply #5 on: October 31, 2019, 10:38:56 AM »
I have wrote the following as I have found limited information on the web on this topic. The Custom Fields are stored in the SummaryInfo Object which is in the document object. I created functions to read, write and delete these custom fields for the active drawing as well as any document object (for ObjectDBX programs).

Code: [Select]
(defun setCustomField (prop value / acad doc summary i notFound key keyVal readVal)
  (if
    (and
      (= 'STR (type prop))
      (= 'STR (type value))
    )
    (progn
      (vl-load-com)
     
      ; Application -> Document -> SummaryInfo
      (setq acad (vlax-get-acad-object))
      (setq doc (vla-get-activedocument acad))
      (setq summary (vla-get-summaryInfo doc))
     
      ; Read if property exist
      (setq i 0)
      (setq notFound T)
      (while
        (and
          (< i (vla-NumCustomInfo summary))
          notFound
        )
        (vl-catch-all-apply 'vla-getCustomByIndex (list summary i 'key 'keyVal))
        (if (= key prop)
          (setq notFound nil)
        )
        (setq i (1+ i))
      )
     
      ; Modify if property exist
      ; Else, create a new property with value
      (if (not notFound)
        (progn
          (vl-catch-all-apply 'vla-setCustomByKey (list summary prop value))
        )
        (progn
          (vl-catch-all-apply 'vla-AddCustomInfo (list summary prop value))
        )
      )
     
      ; Re-Read to verify updated value
      (vl-catch-all-apply 'vla-GetCustomByKey (list summary prop 'readVal))
      (if (= readVal value)
        T
      )
    )
  )
)
(defun readCustomField (prop / acad doc summary i notFound key keyVal readVal)
  (if
    (and
      (= 'STR (type prop))
    )
    (progn
      (vl-load-com)
     
      ; Application -> Document -> SummaryInfo
      (setq acad (vlax-get-acad-object))
      (setq doc (vla-get-activedocument acad))
      (setq summary (vla-get-summaryInfo doc))
     
      ; Re-Read to verify updated value
      (vl-catch-all-apply 'vla-GetCustomByKey (list summary prop 'readVal))
     
      readVal
    )
  )
)
(defun deleteCustomField (prop / acad doc summary readVal)
  (if
    (and
      (= 'STR (type prop))
    )
    (progn
      (vl-load-com)
     
      ; Application -> Document -> SummaryInfo
      (setq acad (vlax-get-acad-object))
      (setq doc (vla-get-activedocument acad))
      (setq summary (vla-get-summaryInfo doc))
     
      ; Re-Read to verify updated value
      (vl-catch-all-apply 'vla-RemoveCustomByKey (list summary prop))
     
      (vl-catch-all-apply 'vla-GetCustomByKey (list summary prop 'readVal))
      (if (not readVal)
        T
      )
    )
  )
)

; For ObjectDBX Programs
(defun JO:setCustomField (doc prop value / acad doc summary i notFound key keyVal readVal)
  (if
    (and
      (= 'STR (type prop))
      (= 'STR (type value))
    )
    (progn
      ; Application -> Document -> SummaryInfo
      (setq summary (vla-get-summaryInfo doc))
     
      ; Read if property exist
      (setq i 0)
      (setq notFound T)
      (while
        (and
          (< i (vla-NumCustomInfo summary))
          notFound
        )
        (vl-catch-all-apply 'vla-getCustomByIndex (list summary i 'key 'keyVal))
        (if (= key prop)
          (setq notFound nil)
        )
        (setq i (1+ i))
      )
     
      ; Modify if property exist
      ; Else, create a new property with value
      (if (not notFound)
        (progn
          (vl-catch-all-apply 'vla-setCustomByKey (list summary prop value))
        )
        (progn
          (vl-catch-all-apply 'vla-AddCustomInfo (list summary prop value))
        )
      )
     
      ; Re-Read to verify updated value
      (vl-catch-all-apply 'vla-GetCustomByKey (list summary prop 'readVal))
      (if (= readVal value)
        T
      )
    )
  )
)
(defun JO:readCustomField (doc prop / acad doc summary i notFound key keyVal readVal)
  (if
    (and
      (= 'STR (type prop))
    )
    (progn
      ; Application -> Document -> SummaryInfo
      (setq summary (vla-get-summaryInfo doc))
     
      ; Re-Read to verify updated value
      (vl-catch-all-apply 'vla-GetCustomByKey (list summary prop 'readVal))
     
      readVal
    )
  )
)
(defun JO:deleteCustomField (doc prop / acad doc summary readVal)
  (if
    (and
      (= 'STR (type prop))
    )
    (progn
      (vl-load-com)
     
      ; Application -> Document -> SummaryInfo
      (setq summary (vla-get-summaryInfo doc))
     
      ; Re-Read to verify updated value
      (vl-catch-all-apply 'vla-RemoveCustomByKey (list summary prop))
     
      (vl-catch-all-apply 'vla-GetCustomByKey (list summary prop 'readVal))
      (if (not readVal)
        T
      )
    )
  )
)

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8658
  • AKA Daniel
Re: Custom AutoCAD Fields
« Reply #6 on: October 31, 2019, 11:15:20 AM »
I used to do the same, you can even copy summaryInfo between drawings, or an external file. I used to import data from our estimation software into summaryInfo, I.e. materials and stuff for use in fields. powerful stuff

Google AcDbDatabaseSummaryInfo, acdbGetSummaryInfo, getCustomSummaryInfo, these are in .net too
I'll look and see if I have any old code

1254582201

  • Guest
Re: Custom AutoCAD Fields
« Reply #7 on: April 10, 2022, 09:59:27 PM »
Hi,
Does the UPDATEFIELD command work?
From an API perspective, you can also update field(s) directly.

You can create your own custom field, there’s an example in one of the ARX SDKs, caveat its C++, so you'll need to translate it to .net.
Its not trivial to do, but not crazy hard
How can I "UPDATEFIELD" with API(not command)?

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8658
  • AKA Daniel

Jeff H

  • Needs a day job
  • Posts: 6144
Re: Custom AutoCAD Fields
« Reply #9 on: April 12, 2022, 11:45:35 AM »

You can create your own custom field, there’s an example in one of the ARX SDKs, caveat its C++, so you'll need to translate it to .net.
Its not trivial to do, but not crazy hard
I cannot find that example, does anyone know if they removed it?

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8658
  • AKA Daniel
Re: Custom AutoCAD Fields
« Reply #10 on: April 12, 2022, 07:44:53 PM »

You can create your own custom field, there’s an example in one of the ARX SDKs, caveat its C++, so you'll need to translate it to .net.
Its not trivial to do, but not crazy hard
I cannot find that example, does anyone know if they removed it?

Looks like it’s been removed.
I know it’s in the ARX SDK for 2009, samples\misc\TextFileField.

I used it for this
https://www.theswamp.org/index.php?topic=56095.0

and this (has source),
https://www.theswamp.org/index.php?topic=28286.0

I thought I had seen field dialog wrappers, but I must have been mistaken.
all I see is:
Autodesk.AutoCAD.ApplicationServices.InplaceTextEditor.FieldDialog(Field)

FWIW, Treat fields as you would a custom object.
If you start using AcDbField::SetData for storing custom data, and make changes, be prepared to be able to evaluate older objects.
Maybe even store a version ID so your evaluator can handle evaluating multiple versions of your custom field.

Cheers:)


BlackBox

  • King Gator
  • Posts: 3770
Re: Custom AutoCAD Fields
« Reply #11 on: April 13, 2022, 07:14:47 AM »
Don't forget that you can implement custom System Variables via Autoloader, etc - and those can be mapped to annotations using Fields.

https://www.theswamp.org/index.php?topic=47842.0
"How we think determines what we do, and what we do determines what we get."

Rustabout

  • Newt
  • Posts: 135
Re: Custom AutoCAD Fields
« Reply #12 on: May 14, 2022, 03:00:35 PM »
There's a few different solutions but before I throw something random out there I just want to confirm that using the Drawing Properties (DWGPROPS) is not a viable option?

I'm new to .NET so still figuring out what's available to me. In AutoLISP there's a lot of different ways one can go about this. The "setcfg" and "getcfg" functions are one option; probably the easiest aside from the drawing properties. XData (complex but works quite well).

The drawing properties are the easiest but can get cluttered quickly. I am considering creating a custom dialog that pulls out only the properties that I need and organizes them how I want them. I believe that out-of-the-box ACAD doesn't allow you to order the properties.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8658
  • AKA Daniel
Re: Custom AutoCAD Fields
« Reply #13 on: May 14, 2022, 08:17:50 PM »
DWGPROPS works very well, one cabinet shop worked for, used them for everything
All the casework blocks were notated with fields, from materials to hardware.
We also had fields for all the title block stuff, Job numbers, Contractor name, address. etc.

Added benefits of using DWGPROPS is you can copy them from drawing <-> drawing, or excel <-> drawing using lisp.
One of the projects I had posted here at the swamp had a palette where you could drag and drop the fields from a list as a mtext or qleader

I agree that organizing them is weird. I guess it’s the reason I created field evaluators for excel and sqlite.

Huge fan of fields, I've begged Bricsys to fix their field dialog, but they won't. I've asked ZwCAD, GsCAD to support custom fields, hoping its in their next release.
So if you need a true custom field evaluator, its Acad only.