Author Topic: Help with annotative text  (Read 6619 times)

0 Members and 1 Guest are viewing this topic.

cmwade77

  • Swamp Rat
  • Posts: 1443
Help with annotative text
« on: June 18, 2008, 08:03:39 PM »

I am trying to use entmake to create annotative text, can anyone tell me what I need to do? The code below creates text all right, but it is not annotative, which is what I need.

Code: [Select]
(setq bei_pt (getpoint))
(entmake (list
'(0 . "TEXT") ; Object type
(cons 1 "TEST TEXT");Text Contents
(cons 7 "-ROMANS-ANNO")
(cons 8  "test") ; Layer
(cons 10 bei_pt) ; Start point
(cons 11 bei_pt) ; End point
(cons 40 0.125);Sets the size of the text (will not create text without this)
(cons 41 0.8); Sets the width factor
(cons 50 0)
(cons 72 1);Ensures the text comes out middle center
(cons 73 2);Ensures the text comes out middle center
))

Adesu

  • Guest
Re: Help with annotative text
« Reply #1 on: June 18, 2008, 09:25:59 PM »
Hi cmwade,
test this code
Code: [Select]
(defun c:test (/ bei_pt stx txs)
  (setq bei_pt (getpoint "\nClick any location: "))
  (setq txs (getvar "TEXTSTYLE"))
  (setq stx "-ROMANS-ANNO")
  (if
    (/= txs stx)
    (command "_style" stx stx "0" "1" "0" "N" "N" "N")
    ) ; if
  (setvar "TEXTSTYLE" stx)
  (command "_layer" "m" "test" "c" 1 "" "")
  (entmake (list '(0 . "TEXT")       ; Object type
(cons 1 "TEST TEXT") ; Text Contents
(cons 7 stx)         ; Text style
(cons 8  "test")     ; Layer
(cons 10 bei_pt)     ; Start point
(cons 11 bei_pt)     ; End point
(cons 40 1.25)       ; Sets the size of the text (will not create text without this)
(cons 41 0.8)        ; Sets the width factor
(cons 50 0)
(cons 72 1)          ; Ensures the text comes out middle center
(cons 73 2)          ; Ensures the text comes out middle center
))
  (princ)
  ) ; defun


I am trying to use entmake to create annotative text, can anyone tell me what I need to do? The code below creates text all right, but it is not annotative, which is what I need.

Code: [Select]
(setq bei_pt (getpoint))
(entmake (list
'(0 . "TEXT") ; Object type
(cons 1 "TEST TEXT");Text Contents
(cons 7 "-ROMANS-ANNO")
(cons 8  "test") ; Layer
(cons 10 bei_pt) ; Start point
(cons 11 bei_pt) ; End point
(cons 40 0.125);Sets the size of the text (will not create text without this)
(cons 41 0.8); Sets the width factor
(cons 50 0)
(cons 72 1);Ensures the text comes out middle center
(cons 73 2);Ensures the text comes out middle center
))

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Help with annotative text
« Reply #2 on: June 18, 2008, 09:38:20 PM »
Look at DXF code 10 & 11.
Code: [Select]
;; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;; =    T E X T   O B J E C T 
;; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=
(entmakex (list (cons 0 "TEXT") ;***
               (cons 1 "") ;* (the string itself)
               (cons 6 "BYLAYER") ; Linetype name
               (cons 7 "STANDARD") ;* Text style name, defaults to STANDARD, not current
               (cons 8 "0")   ; layer
               (cons 10 (list 0.0 0.0 0.0)) ;* First alignment point (in OCS)
               (cons 11 (list 0.0 0.0 0.0)) ;* Second alignment point (in OCS)
               (cons 39 0.0) ; Thickness (optional; default = 0)
               (cons 40 1.0) ;* Text height
               (cons 41 1.0) ; Relative X scale factor, Width Factor, defaults to 1.0
               (cons 50 0.0) ; Text rotation ange
               (cons 51 0.0) ; Oblique angle
               (cons 62 256) ; color
               (cons 71 0) ; Text generation flags
               (cons 72 0) ; Horizontal text justification type
               (cons 73 0) ; Vertical text justification type
               (cons 210 (list 0.0 0.0 1.0))))
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.

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Help with annotative text
« Reply #3 on: June 19, 2008, 11:00:24 AM »
I thought 10 & 11 were the start end end points? How do I use those to make the text annotative?

Ok, I havfe tried both with no luck, again, the text gets created, but without being annotative.
« Last Edit: June 19, 2008, 11:42:14 AM by cmwade77 »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Help with annotative text
« Reply #4 on: June 19, 2008, 11:41:50 AM »
Let me retract my statement as I'm just realizing that you are talking about ACAD2008 associative text.
I am unfamiliar with the DXF codes for that object. If I find anything I'll get back to you.
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.

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Help with annotative text
« Reply #5 on: June 19, 2008, 11:49:34 AM »
Thank you, sorry, yes that was what I was looking for, I am really trying to avoid using commands, as they tend to be slower and there are going to be a fair number of them used here.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Help with annotative text
« Reply #6 on: June 19, 2008, 12:20:06 PM »
To add annotative scales, you have to add them to the extension dictionary of the object.
Tim

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

Please think about donating if this post helped you.

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Help with annotative text
« Reply #7 on: June 19, 2008, 12:41:55 PM »
Not trying to add annotative scales, we use 2009 and it now adds them automatically  :-D

I am trying to create the text as annotative text using entmake, I just can't figure out how to tell it that I want the text to be annotative.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Help with annotative text
« Reply #8 on: June 19, 2008, 01:10:35 PM »
To make a text entity annotative, it has to have scales within the definition of the entity ( dxf codes ), and to do that you have to create an extension dictionary to that object, and then place the annotative scales that you want associated with that object there in the dictionary.  That is if I'm reading this correctly, and you are wanting text entities to be annotative, and not text styles.
Tim

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

Please think about donating if this post helped you.

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Help with annotative text
« Reply #9 on: June 19, 2008, 07:42:21 PM »
You are indeed reading this correctly, but I have no idea how to do any of what you just said, I thought I do a decent job with programming, but a lot of that went over my head.

Crank

  • Water Moccasin
  • Posts: 1503
Re: Help with annotative text
« Reply #10 on: June 20, 2008, 02:14:34 PM »
This is very complicated to do and a lot of work. There are also a lot of error traps, because this is not documented.

With dbview.arx it's possible to see the structure of the database:
  • You have to check if 'AcadAnnotative' is present or add it to the Registered Annotation Table
  • All scales you want to add must be present in the scalelist dictionary: ACAD_SCALELIST
  • Your text needs pointers to the scales of the scalelist that you want to add.
  • The text also needs a flag set so Autocad knows the annotative scaling is on.

Of course it's much easier to use COMMAND.
It wouldn't surprise me if all those dictionary's will change with the next .dwg-standard. In that case your code wouldn't work any more.
Vault Professional 2023     +     AEC Collection

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Help with annotative text
« Reply #11 on: June 20, 2008, 02:22:07 PM »
I had started some, but it doesn't work the way it should.  It adds the annotative'ness to it, but the text then disappears.  The text won't appear when you switch to the scale you add.

So this is a work in progress ( and I wouldn't use on any real drawing ), but I welcome anyones help on it.  To me it is just a learning experience, as I'm still on '06.

Code: [Select]
(defun c:AddAnnoScale (/ Sel EntData tempType ScList cnt Opt Sc ExDict DataMan AnnoSc tempList ScName tempScList)
   
    (defun GetAnnoScales (/ ScList)
       
        (foreach i (dictsearch (namedobjdict) "ACAD_SCALELIST")
            (if (equal (car i) 350)
                (setq ScList (cons (cons (cdr (assoc 300 (entget (cdr i)))) (cdr i)) ScList))
            )
        )
        ScList
    )
    ;---------------------------
    (defun CreateExDict (ent / EntData)
       
        (setq EntData (entget ent))
        (cdr
            (assoc
                360
                (entmod
                    (append
                        EntData
                        (list
                            '(102 . "{ACAD_XDICTIONARY")
                            (cons
                                360
                                (entmakex
                                    '(
                                        (0 . "DICTIONARY")
                                        (100 . "AcDbDictionary")
                                        (280 . 0)
                                        (281 . 1)
                                    )
                                )
                            )
                            '(102 . "}")
                        )
                    )
                )
            )
        )
    )
    ;---------------------------------------------------------

    (if
        (and
            (setq Sel (entsel "\n Select text to add scale to: "))
            (setq EntData (entget (car Sel)))
            (setq tempType (cdr (assoc 0 EntData)))
            (or
                (= tempType "TEXT")
                (= tempType "MTEXT")
            )
            (setq ScList (GetAnnoScales))
            (setq cnt 0)
            (progn
                (foreach i ScList
                    (prompt (strcat "\n " (itoa cnt) " - " (car i)))
                    (setq cnt (1+ cnt))
                )
                (setq cnt (1- cnt))
                (textscr)
                (while
                    (not
                        (<=
                            0
                            (setq Opt (getint (strcat "\n Enter number of scale to add [ 0 - " (itoa cnt) " ]: ")))
                            cnt
                        )
                    )
                )
                (graphscr)
                (setq Sc (cdr (nth Opt ScList)))
            )
            (setq ExDict
                (cond
                    ((cdr (assoc 360 EntData)))
                    ((CreateExDict (car Sel)))
                )
            )
            (setq DataMan
                (cond
                    ((setq tempData (dictsearch ExDict "AcDbContextDataManager"))
                        (cdr (assoc -1 tempData))
                    )
                    (
                        (dictadd
                            ExDict
                            "AcDbContextDataManager"
                            (entmakex
                                (list
                                    '(0 . "DICTIONARY")
                                    '(100 . "AcDbDictionary")
                                    '(280 . 0)
                                    '(281 . 1)
                                )
                            )
                        )
                    )
                )
            )
            (if
                (setq AnnoSc
                    (cond
                        ((setq tempData (dictsearch DataMan "ACDB_ANNOTATIONSCALES"))
                            (cdr (assoc -1 tempData))
                        )
                        (
                            (dictadd
                                DataMan
                                "ACDB_ANNOTATIONSCALES"
                                (entmakex
                                    (list
                                        '(0 . "DICTIONARY")
                                        '(100 . "AcDbDictionary")
                                        '(280 . 0)
                                        '(281 . 1)
                                    )
                                )
                            )
                        )
                    )
                )
                (progn
                    (setq tempData (entget AnnoSc))
                    (foreach i tempData
                        (cond
                            ((equal (car i) 3)
                                (setq tempList (cons (cdr i) tempList))
                            )
                            ((equal (car i) 350)
                                (setq tempScList (cons (cdr (assoc 340 (entget (cdr i)))) tempScList))
                            )
                        )
                    )
                    (if (not (member Sc tempScList))
                        (progn
                            (setq ScName
                                (if tempList
                                    (progn
                                        (strcat
                                            "*A"
                                            (itoa
                                                (1+
                                                    (atoi
                                                        (substr
                                                            (car
                                                                (vl-sort
                                                                    tempList
                                                                    '(lambda (a b)
                                                                        (> (atoi (substr a 3)) (atoi (substr b 3)))
                                                                    )
                                                                )
                                                            )
                                                            3
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                    (progn
                                        (entmod
                                            (append
                                                EntData
                                                (list
                                                    (list
                                                        -3
                                                        (list
                                                            "AcadAnnotative"
                                                            '(1000 . "AnnotativeData")
                                                            '(1002 . "{")
                                                            '(1070 . 1)
                                                            '(1070 . 1)
                                                            '(1002 . "}")
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                        "*A1"
                                    )
                                )
                            )
                            (dictadd
                                AnnoSc
                                ScName
                                (entmakex
                                    (list
                                        '(0 . "ACDB_TEXTOBJECTCONTEXTDATA_CLASS")
                                        '(100 . "AcDbObjectContextData")
                                        (cons 70 3)
                                        (cons 290 1)
                                        '(100 . "AcDbAnnotScaleObjectContextData")
                                        (cons 340 Sc)
                                        (cons 70 0)
                                        (assoc 50 EntData)
                                        (assoc 10 EntData)
                                        (assoc 11 EntData)
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
        (prompt (strcat "\n Added scale " (car (nth Opt ScList)) " sucessfully to entity."))
    )
    (princ)
)
Tim

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

Please think about donating if this post helped you.