Author Topic: replace xrecord attached to object  (Read 2690 times)

0 Members and 1 Guest are viewing this topic.

Amsterdammed

  • Guest
replace xrecord attached to object
« on: May 28, 2013, 02:54:05 PM »
I know this might have been covered here before (i was searching but could not make it work) but i'm in need for help with this problem. I have an object with xrecords attached and i need to change them. Idid this with entmod and got the result (i thought) but i also doubled the size of the xrecord, because it added the code instead of replacing it.

I tried MP's AddOrReplaceXrec function but can't make it work  :cry:

Any help would be very appreciated!

i attach the object and the code
Code: [Select]
(defun x_data_put_nqp_sub (ent sub what new / el TMP1)
  (setq el     (entget ent
                       (list "*")
                       ) ;_ end of entget

        data   (reverse (cdr (ASSOC -3 EL)))
        nDATA  nil
        flag   nil
        result nil
        ) ;_ end of setq
;;;
  (setq prefix
         (cond ((= (type new) 'STR)
                1000
                )
               ((= (type new) 'INT)
                1070
                )
               ((= (type new) 'REAL)
                1040
                )

               ) ;_ end of cond
        ) ;_ end of setq
  (setq pair (cons prefix new))
  (setq WHATL (CONS 1000 WHAT))





;;;







  (setq prefix
         (cond ((= (type new) 'STR)
                1
                )
               ((= (type new) 'INT)
                70
                )
               ((= (type new) 'REAL)
                40
                )

               ) ;_ end of cond
        ) ;_ end of setq
  (setq npair (cons prefix new))
  (setq WHATL (CONS 1 WHAT))




  (setq pair  (cons 3 sub)
        el_np (entget ent (list "*"))
        )                           
  (IF (and (CDR (ASSOC 102 el_np))
           (assoc 360 (ENTGET (cdr (assoc 360 el_np))))
           ) ;_ end of and
    (PROGN
      (setq dic
             (entget
               (cdr (assoc 360 (ENTGET (cdr (assoc 360 el_np)))))
               ) ;_ end of entget
            ) ;_ end of setq
      (if (member pair dic)
        (progn
          (setq dicent (cdr (assoc 360 (member pair dic))))
          (setq dicel (entget dicent))
;;;(setq ndicel(subst npair (assoc 40 (member WHATL dicel))(member WHATL dicel)))
          (setq
            ndicel (subst
                     npair
                     (if (and (= Sub "Nordined.Technics.Conn.3")
                              (= "Position" (cdr whatl))
                              ) ;_ end of and
                       (nth (+ 3 (vl-position whatl dicel)) dicel)
                       (nth (1+ (vl-position whatl dicel)) dicel)
                       ) ;_ end of if
                     dicel
                     ) ;_ end of subst
            ) ;_ end of setq

          (entmod ndicel)
;;;(AddOrReplaceXrec (cdr (assoc -1 ndicel)) (cdr pair)(cdr(member '(280 . 1)ndicel)));;test 29-05-013



          ) ;_ end of progn
        ) ;_ end of if
      ) ;_ end of PROGN
    ) ;_ end of IF
  )


(x_data_put_nqp_sub
        (car (entsel))
        "Nordined.Technics.Conn.2"
        "Position"
        50.0
        )





;_ end of defun
;|«Visual LISP© Format Options»
(72 2 40 1 T "end of " 60 9 0 0 0 nil T nil T)
;*** DO NOT add text below the comment! ***|;





MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: replace xrecord attached to object
« Reply #1 on: May 28, 2013, 03:19:36 PM »
If memory serves you cannot replace xrecords. You have to delete and create, replicating former existing data to suit to yield the effect of replacing the xrecord, being mindful the xrecord's handle will change, and any pointers to it will need to reflect same. Run on sentence ran on; oh well.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Amsterdammed

  • Guest
Re: replace xrecord attached to object
« Reply #2 on: May 29, 2013, 03:12:00 AM »
that is all understood, the how is the problem....



Anestis

  • Guest
Re: replace xrecord attached to object
« Reply #3 on: March 24, 2015, 04:33:16 PM »
If memory serves you cannot replace xrecords. You have to delete and create, replicating former existing data to suit to yield the effect of replacing the xrecord, being mindful the xrecord's handle will change, and any pointers to it will need to reflect same. Run on sentence ran on; oh well.
Firstly, hello to all and sorry for my English.
I know that this is an old post and having searched through the forum I found the above answer everywhere.
Even these have not provided an explanation to me :
http://www.theswamp.org/index.php?topic=39924.msg452285#msg452285
Still I find myself compelled to ask this :
Why are there the 280 and 281 group codes in XRECORD and DICTIONARY objects respectively?
What is their function? What does : "Duplicate record cloning flag" "2 = use clone" actually mean?
My reading of the corresponding help files tells me that their function is exactly the intended in this thread, so why is it not working, however I try to implement the "use clone" mentioned in help.
Any thoughts or info will be greatly appreciated.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: replace xrecord attached to object
« Reply #4 on: March 24, 2015, 05:59:59 PM »
Quick response from mobile -- codes 280/281, either in concert or individually flag the entry is hard owned (ie will survive wblocking etc).
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Anestis

  • Guest
Re: replace xrecord attached to object
« Reply #5 on: March 26, 2015, 05:31:18 AM »
Still, let me focus on the DICTIONARY first: reading from the help files :
"DICTIONARY group codes
[...]
280 Hard-owner flag. If set to 1, indicates that elements of the dictionary are to be treated as hard-owned

281 Duplicate record cloning flag (determines how to merge duplicate entries):
       0 = Not applicable
       1 = Keep existing
       2 = Use clone
       3 = <xref>$0$<name>
       4 = $0$<name>
       5 = Unmangle name
[...]"

I would tend to agree that it is a matter of inter-file behavior, were it not for the specific phrasing used above:
281 [...] (determines how to merge duplicate entries)
and furthermore there is the 280 already there.

I have already created my dictionary :
((-1 . <Entity name: 7ff76e211ee0>) (0 . "DICTIONARY") (5 . "D07E") (102 . "{ACAD_REACTORS") (330 . <Entity name: 7ff76e211ea0>) (102 . "}") (330 . <Entity name: 7ff76e211ea0>) (100 . "AcDbDictionary") (280 . 0) (281 . 2) (3 . "TESTXREC") (350 . <Entity name: 7ff76e212060>))

and when I ran the following twice : (ak_test_dic_en holds my dictionary's entity name)
Code: [Select]
(defun xrectestadd ( / )
(dictadd ak_test_dic_en "TESTXREC"
(entmakex (list '(0 . "XRECORD") '(100 . "AcDbXrecord") '(280 . 2) (cons 300 "2B07" ) ) )
)
)

The result is (granted, as already stated but still not clear why) :
((-1 . <Entity name: 7ff76ec126e0>) (0 . "XRECORD") (5 . "D1CD") (102 . "{ACAD_REACTORS") (330 . <Entity name: 7ff76ec11ee0>) (102 . "}") (330 . <Entity name: 7ff76ec11ee0>) (100 . "AcDbXrecord") (280 . 2) (300 . "2B07"))
whereas the second run of the code it returned nil.

Maybe is it an "inheritance" thing from the (namedobjdict) where my dictionary resides??? But, doesn't everything in a dwg file end up residing in there?

And, as a last thought, in the second to last paragraph of this very helpful tutorial, it is stated :
Sometimes when updating a Dictionary it's easier to remove/delete it and replace it with a new entry, but that will be for your pleasure to explore.

I am currently in that exact procedure of exploring when it is best to do what , but I am not finding it very pleasurable  :-P

I know what to do for reading my entries and re-creating them, but since I intend to be able to do it for many, many objects (somewhere in the thousands), I know that a replacing technique would be more efficient. Still, if there absolutely is no way that can be done, then I would search for other ways to do it, or settle for slow. Currently, I hope there will be a way, reading the signs above as I have, and am hopeful that I or someone else will help go there.
« Last Edit: March 26, 2015, 05:56:21 AM by Anestis »

Anestis

  • Guest
Re: replace xrecord attached to object
« Reply #6 on: March 26, 2015, 05:47:05 AM »
A little addition:
when running , after creating the first Xrecord with the above code, the following :
Code: [Select]
(defun xrectestmod ( / ) ; ak_test_dic_en holds the dictionary's entity name
(entmod
(subst (cons 300 "new2B07" )
(assoc 300 (dictsearch ak_test_dic_en "TESTXREC") )
(dictsearch ak_test_dic_en "TESTXREC")
)
)
(princ)
)

The result is, as currently expected but not wanted (as most things in life)  :
((-1 . <Entity name: 7ff76e212850>) (0 . "XRECORD") (5 . "D1CD") (102 . "{ACAD_REACTORS") (330 . <Entity name: 7ff76e211ee0>) (102 . "}") (330 . <Entity name: 7ff76e211ee0>) (100 . "AcDbXrecord") (280 . 2) (300 . "2B07") (300 . "new2B07"))
the appending of the new data to the old one.
I am going to explore the possibility that the 280/281 dxf codes refer to inter-file behaviour... will get back on that