Author Topic: Update to Annotative  (Read 2668 times)

0 Members and 1 Guest are viewing this topic.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4076
Update to Annotative
« on: September 21, 2010, 01:48:18 PM »
I have an idea for a new program, one that updates objects to annotative state, using user selected defaults.  Has anybody seen anything like this before?  I dont want to reinvent the wheel if possible.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Update to Annotative
« Reply #1 on: September 21, 2010, 02:14:03 PM »
I haven't, but I know it was a pain in Lisp, so I hope .Net is better suited for this if you pursue it.
Tim

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

Please think about donating if this post helped you.

Jeff H

  • Needs a day job
  • Posts: 6151
Re: Update to Annotative
« Reply #2 on: September 21, 2010, 05:36:04 PM »
When you say Annotative state do you mean like ANNOUPDATE ALL and ANNORESET ALL

Or like text with textStyle be annotative or however you want to filter it



David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4076
Re: Update to Annotative
« Reply #3 on: September 22, 2010, 10:44:59 AM »
I was thinking about how to automate the process I have been doing all day.  Basically, I am fixing a legacy drawing, updating to our new standards as I go.  Which would mean annotative everything.  What I was thinking was if I had a dialog box that listed the relevant anno styles in the drawing, I could pick my defaults, then select a bunch of objects.  If the object can be anno, it checks to see what "default" I set for that type.  So all text would be style 'X', all my dims would be DimStyle 'Y', etc.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

kaefer

  • Guest
Re: Update to Annotative
« Reply #4 on: September 22, 2010, 12:38:35 PM »
I was thinking about how to automate the process I have been doing all day.  Basically, I am fixing a legacy drawing, updating to our new standards as I go.  Which would mean annotative everything.  What I was thinking was if I had a dialog box that listed the relevant anno styles in the drawing, I could pick my defaults, then select a bunch of objects.  If the object can be anno, it checks to see what "default" I set for that type.  So all text would be style 'X', all my dims would be DimStyle 'Y', etc.

Now that's a slightly different kettle of fish: You want to apply a CAD standard to your drawing, and on top of that, you'd like it annotative. This last part looks positively easy.

To convert a DBObject to annotative state, you'd have basically 1) add the context for "ACDB_ANNOTATIONSCALES" to the object and 2) update the corresponding XData.

I tried to do that in my beloved F#, and was successfull so far for DBText, MText, Hatch and Dimension. See for yourself:
Code: [Select]
open Autodesk.AutoCAD.DatabaseServices
open Autodesk.AutoCAD.EditorInput
open Autodesk.AutoCAD.Geometry
open Autodesk.AutoCAD.Runtime

// Constants for XData
let regAppName = "AcadAnnotative"
let annoXData =
    [   new TypedValue(int DxfCode.ExtendedDataAsciiString, "AnnotativeData")
        new TypedValue(int DxfCode.ExtendedDataControlString, "{")
        new TypedValue(int DxfCode.ExtendedDataInteger16, 1s)
        new TypedValue(int DxfCode.ExtendedDataInteger16, 1s)
        new TypedValue(int DxfCode.ExtendedDataControlString, "}") ]

// Pattern for TypedValue matching
let (|TypedValue|) (tv: TypedValue) = tv.TypeCode, tv.Value

// Type extension for XData handling   
type ResultBuffer with
    member rb.toMap =
        let rec rb2tv acc (m: Map<_,_>) =
            function
            | TypedValue(k, v) :: xs when
                k = int16 DxfCode.ExtendedDataRegAppName ->
                    rb2tv [] (m.Add(unbox<string> v, acc)) xs
            | tv :: xs ->
                rb2tv (tv :: acc) m xs
            | _ -> m
       
        match rb with
        | null -> Map.empty
        | _ -> rb2tv [] Map.empty ((Seq.cast >> Seq.toList >> List.rev) rb)

    static member ofMap (m: Map<_,_>) =
        [|  for KeyValue(k, v) in m do
                yield(
                    new TypedValue(
                        int DxfCode.ExtendedDataRegAppName, box k ) )
                yield! v |]
        |> fun a -> new ResultBuffer(a)

[<CommandMethod "FOO">]
let foo() =
    let db = HostApplicationServices.WorkingDatabase
    use tr = db.TransactionManager.StartTransaction()

    // Might be ok not to check for regAppName
    let rat = tr.GetObject(db.RegAppTableId, OpenMode.ForRead) :?> RegAppTable
    if not(rat.Has regAppName) then
        rat.UpgradeOpen()
        let ratr = new RegAppTableRecord(Name = regAppName)
        tr.AddNewlyCreatedDBObject(ratr, true)
        rat.Add(ratr) |> ignore
   
    // Context collection stores the extension dict contents
    let occ =
        db.ObjectContextManager.GetContextCollection(
            "ACDB_ANNOTATIONSCALES" )
    let ms =
        tr.GetObject(
            SymbolUtilityServices.GetBlockModelSpaceId db,
            OpenMode.ForRead ) :?> BlockTableRecord
    for oid in ms do
        let dbo = tr.GetObject(oid, OpenMode.ForRead) // DBObject
        match dbo with
        | :? DBText
        | :? MText
        | :? Hatch
        | :? Dimension ->
                dbo.UpgradeOpen()
                // Add context
                Autodesk.AutoCAD.Internal.ObjectContexts.AddContext(
                    dbo, occ.CurrentContext )
                // Add XData
                let xdata = dbo.XData.toMap
                use rb = xdata.Add(regAppName, annoXData) |> ResultBuffer.ofMap
                dbo.XData <- rb
                dbo.DowngradeOpen()
        | _ -> ()
    tr.Commit()

Regards, Thorsten

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4076
Re: Update to Annotative
« Reply #5 on: September 23, 2010, 02:53:20 PM »
I will have to give that a read later, thanks Thorsten
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)