• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Valued Contributor
    GrzesiekGP
    Posts: 54
    Registered: ‎02-03-2012
    Accepted Solution

    Save some variables into DWG file - how? C#.

    449 Views, 19 Replies
    09-12-2012 10:13 AM

    Hello!

     

    Please let me know if I'm able to save some variables into current DWG?

     

    I would like to provide availability for user to save some data which is different for each DWG file.

     

    Thanks.

    Please use plain text.
    *Expert Elite*
    arcticad
    Posts: 1,250
    Registered: ‎06-21-2004

    Re: Save some variables into DWG file - how? C#.

    09-12-2012 10:47 AM in reply to: GrzesiekGP

    Lookup Xrecords / Xdata and Dictionary

    http://through-the-interface.typepad.com/through_the_interface/2007/04/adding_xdata_to.html

    http://through-the-interface.typepad.com/through_the_interface/2012/02/dynamic-net-in-autocad-2013.h...

    ---------------------------



    “We don’t have a snowball’s chance in a blast furnace of surviving this attack unless every one of our units gets into the fight right now!”
    Please use plain text.
    ADN Support Specialist
    Posts: 261
    Registered: ‎05-22-2006

    Re: Save some variables into DWG file - how? C#.

    09-12-2012 11:52 AM in reply to: arcticad

    Further to arcticad's reply, you'd typically store global data on the Named Objects Dictionary, and data related to a particular entity as xdata on that entity or as an xrecord in its extension dictionary.

     

    But if you're storing 'variables' (sysvars), then you migh prefer to use the Autodesk.AutoCAD.Runtime.Variable class. You can specify whether the variable is per session, per user, per profile or per database.

     

     

    Cheers,

    Stephen Preston
    Autodesk Developer Network
    Please use plain text.
    *Expert Elite*
    arcticad
    Posts: 1,250
    Registered: ‎06-21-2004

    Re: Save some variables into DWG file - how? C#.

    09-12-2012 01:17 PM in reply to: StephenPreston

    I don't seem to find any information on how to use Autodesk.AutoCAD.Runtime.Variable

    Can you point me in the direction.

    Thanks.

    ---------------------------



    “We don’t have a snowball’s chance in a blast furnace of surviving this attack unless every one of our units gets into the fight right now!”
    Please use plain text.
    Active Contributor
    RichardCammeray
    Posts: 35
    Registered: ‎12-08-2010

    Re: Save some variables into DWG file - how? C#.

    09-12-2012 05:02 PM in reply to: GrzesiekGP

    I used LispVariable to store data in file so user could use them in Text Field.

    Here are examples how to get and set Lisp Variables I used.

    http://www.theswamp.org/index.php?topic=35714.0

     

    Richard.

    Please use plain text.
    Active Contributor
    RichardCammeray
    Posts: 35
    Registered: ‎12-08-2010

    Re: Save some variables into DWG file - how? C#.

    09-12-2012 05:22 PM in reply to: GrzesiekGP

    I forgot to say then these variables are not saved in drawing.

    Richard

    Please use plain text.
    Valued Contributor
    GrzesiekGP
    Posts: 54
    Registered: ‎02-03-2012

    Re: Save some variables into DWG file - how? C#.

    09-12-2012 10:28 PM in reply to: GrzesiekGP

    Thank you for the links.

     

    Following the first, I have question - am I able to set my XData without selecting an entity?

    Please use plain text.
    *Expert Elite*
    Posts: 1,640
    Registered: ‎04-29-2006

    Re: Save some variables into DWG file - how? C#.

    09-12-2012 10:35 PM in reply to: arcticad

    Hi articad,

     

    You can see this thread about custom Variables.

    IMO, the main issue with Autodesk.AutoCAD.Runtim.Variable is the variable has to be registered in HKLM which most often requires administrator user account.

    Gilles Chanteau
    Please use plain text.
    Active Contributor
    RichardCammeray
    Posts: 35
    Registered: ‎12-08-2010

    Re: Save some variables into DWG file - how? C#.

    09-12-2012 10:41 PM in reply to: GrzesiekGP

    Use DBDictionary to save data (XRecord) in file.

    Try to search for   NamedObjectsDictionary (NOD) you should find many examples in this forum.

     

    Richard

    Please use plain text.
    *Expert Elite*
    Posts: 1,640
    Registered: ‎04-29-2006

    Re: Save some variables into DWG file - how? C#.

    09-12-2012 10:43 PM in reply to: GrzesiekGP

    Hi GrzesiekGP,

     

    If you want to go the Xdata route without selecting an entity, you can set your Xdata on any DBObject (i.e. layer "0", model space BlockTableRecord) but, IMO, you'd rather use a DBDictionary and Xrecord.

    Gilles Chanteau
    Please use plain text.