Author Topic: Xref 2 Block  (Read 17282 times)

0 Members and 1 Guest are viewing this topic.

GDF

  • Water Moccasin
  • Posts: 2081
Xref 2 Block
« on: January 18, 2006, 11:09:25 AM »
I have a good Xref 2 Block routine by Chad Wanless. I am looking for a good Xref 2 Block routine.

The following code works only for inserting a block from an xref.

Code: [Select]
(defun C:X2B  (/ bn1 cnt plc xrn1 BNN xbn1)
  (princ "\n* Reference File Block Insert *")
  (setvar "cmdecho" 0)
  (setq BN1
         (cdr
           (assoc 2
                  (entget
                    (nth 0 (nth 3 (nentsel "\n* Select block in XRef file to insert *")))))))
  (setq cnt t
        plc 1)
  (while cnt
    (setq x (substr bn1 plc 1))
    (if (= x "|")
      (setq cnt nil))
    (setq plc (1+ plc)))
  (command "xbind" "b" BN1)
  (setq xrn1 (substr BN1 1 (- plc 2)))
  (setq BNN (substr BN1 plc))
  (setq xbn1 (strcat xrn1 "$0$" bnn))
  (command "rename" "b" xbn1 bnn)
  (command "insert" bnn)
  (princ))
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Xref 2 Block
« Reply #1 on: January 18, 2006, 11:28:59 AM »
I have a good Xref 2 Block routine by Chad Wanless. I am looking for a good Xref 2 Block routine.
You lost me?  What are you looking for?
Tim

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

Please think about donating if this post helped you.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Xref 2 Block
« Reply #2 on: January 18, 2006, 12:23:32 PM »
Sorry, I was not very clear. I am looking for a Xref 2 Block routine that will make a block out of an attached xref and modify the
layers with a bind insert approach. In other words, only make a block out of only the on and thawed layers within the attached xref.

This was a request from a fellow coworker. In otherwords an opposite approach from the "Block to Xref" by (c)2000, Chad Wanless.

The code I posted will only insert a block taken from the attached xref.

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Xref 2 Block
« Reply #3 on: January 18, 2006, 01:38:35 PM »
See if this is what you are looking for.  I tried to do it without ObjectDBX, but it didn't seem to work.  I left in that portion, but commented it out.  If anyone can see a flaw in that way that I missed, please post.
Code: [Select]
(defun c:XrefBlockInsert (/ ActDoc BlkCol LayCol Sel EntData BlkName BlkRefObj LayList NewBlk FullPath dbxApp ObjList)

(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(setq BlkCol (vla-get-Blocks ActDoc))
(setq LayCol (vla-get-Layers ActDoc))
(if
 (and
  (setq Sel (entsel "\n Select Xref to turn into block: "))
  (setq EntData (entget (car Sel)))
  (= (cdr (assoc 0 EntData)) "INSERT")
  (setq BlkName (cdr (assoc 2 EntData)))
  (setq BlkRefObj (vla-item BlkCol BlkName))
  (= (vla-get-IsXref BlkRefObj) :vlax-true)
 )
 (progn
  (vlax-for i LayCol
   (if
    (and
     (wcmatch (setq LayName (vla-get-Name i)) (strcat BlkName "|*"))
     (= (vla-get-LayerOn i) :vlax-true)
     (= (vla-get-Freeze i) :vlax-false)
    )
;    (setq LayList (cons LayName LayList))
    (setq LayList (cons (substr LayName (+ 2 (strlen BlkName))) LayList))
   )
  )
  (setq NewBlk (vla-Add BlkCol (vla-get-Origin BlkRefObj) (strcat "BlockofXref-" BlkName)))
  (if (setq FullPath (findfile (vla-get-Path (vlax-ename->vla-object (car Sel)))))
   (progn
    (setq dbxApp
     (if (< (atoi (setq oVer (substr (getvar "acadver") 1 2))) 16)
      (vla-GetInterfaceObject (vlax-get-acad-object) "ObjectDBX.AxDbDocument")
      (vla-GetInterfaceObject (vlax-get-acad-object) (strcat "ObjectDBX.AxDbDocument." oVer))
     )
    )
    (vla-Open dbxApp FullPath)
    (vlax-for i (vla-get-ModelSpace dbxApp)
     (if (vl-position (vla-get-Layer i) LayList)
      (setq ObjList (cons i ObjList))
     )
    )
    (vlax-invoke dbxApp 'CopyObjects ObjList NewBlk)
    (prompt (strcat "\n New block created name \"BlockofXref-" BlkName "\"."))
   )
   (progn
    (prompt "\n Can not find darwing to open.")
    (vla-Delete NewBlk)
   )
  )
  (vlax-release-object dbxApp)
  (setq dbxApp nil)
;  (vlax-for i (vla-get-ModelSpace (vla-get-XrefDatabase BlkRefObj))
;   (if (vl-position (vla-get-Layer i) LayList)
;    (setq ObjList (cons i ObjList))
;   )
;  )
;  (vlax-invoke (vla-get-XrefDatabase BlkRefObj) 'CopyObjects ObjList NewBlk)
 )
)
(princ)
)
Tim

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

Please think about donating if this post helped you.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Xref 2 Block
« Reply #4 on: January 18, 2006, 02:37:12 PM »
Tim

Yes, that works perfectly.
Thank you and the coworker who requested it wants to marry you.

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Xref 2 Block
« Reply #5 on: January 18, 2006, 02:41:11 PM »
Glad it works for you/her.  I hope it is a her.   :evil:
I AM single, age 28.  :lmao:

Had to add it.  It's a good day right now.
Tim

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

Please think about donating if this post helped you.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Xref 2 Block
« Reply #6 on: January 18, 2006, 02:52:52 PM »
Tim

Frank <the coworker> is 43 and he thanks you. He has bugged me for days for this routine. So I thank you for getting him off my back....yes it is a good day.

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Greg B

  • Seagull
  • Posts: 12417
  • Tell me a Joke!
Re: Xref 2 Block
« Reply #7 on: January 18, 2006, 02:57:48 PM »
Frank <the coworker> is 43 and he thanks you.


Sounds perfect for you Tim.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Xref 2 Block
« Reply #8 on: January 18, 2006, 02:59:10 PM »
Oh well.  You and Frank are welcome.  I like helping, when I have time.

Frank <the coworker> is 43 and he thanks you.


Sounds perfect for you Tim.
Not at this point in my life.  :-D  I'm still waiting for that ONE girl to come along.
Tim

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

Please think about donating if this post helped you.

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
Re: Xref 2 Block
« Reply #9 on: January 18, 2006, 05:34:40 PM »
... I am looking for a Xref 2 Block routine that will make a block out of an attached xref and modify the
layers with a bind insert approach. In other words, only make a block out of only the on and thawed layers within the attached xref.

We interrupt this broadcast to bring you a special report ....

Just found out today ... microstation has that built-in. Really cool feature.
Sorry .... had to through that in there.   :lmao:

Now back to As the World Turns ......
TheSwamp.org  (serving the CAD community since 2003)

LE

  • Guest
Re: Xref 2 Block
« Reply #10 on: January 18, 2006, 05:39:46 PM »

We interrupt this broadcast to bring you a special report ....

Just found out today ... microstation has that built-in. Really cool feature.
Sorry .... had to through that in there.   :lmao:

Now back to As the World Turns ......

Have you used already the "terminator" ? ... how do you like the nested copy ?.... the what you see, what you get thing... much better than acad no?

LE

  • Guest
Re: Xref 2 Block
« Reply #11 on: January 18, 2006, 05:44:22 PM »
Also, how about the copy parallel.... nice no?... well I am talking about intergraph ms 4.0/5.0....
« Last Edit: January 18, 2006, 05:48:28 PM by LE »

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
Re: Xref 2 Block
« Reply #12 on: January 18, 2006, 05:49:41 PM »
Have you used already the "terminator" ? ... how do you like the nested copy ?

Haven't seen those yet Luis, I'll check'em out tomorrow though.
TheSwamp.org  (serving the CAD community since 2003)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Xref 2 Block
« Reply #13 on: January 18, 2006, 07:29:28 PM »
I have a question for the Gurus.  I know you are supposed to release objects that you use, especially when using them with ObjectDBX.  Do I need to release all the objects that I put into the list to be copied over?
Tim

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

Please think about donating if this post helped you.

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: Xref 2 Block
« Reply #14 on: January 18, 2006, 10:00:11 PM »
Do I need to release all the objects that I put into the list to be copied over?
With ODBX the only thing I release is the ODBX object itself and I've never seen any "bad things" happen. OTOH, when working with LandDesktop objects, especially surfaces, if I don't release EACH & EVERY object, in the EXACT reverse order of their creation, I can amost guarantee a crash within 5 minutes.

Somewhere on theSwamp, Kerry Brown posted about some tests he had run and had even asked the programmers at Autodesk about. HERE IT IS The whole thread should be interesting reading for you.