TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: GDF on January 18, 2006, 11:09:25 AM

Title: Xref 2 Block
Post by: GDF 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))
Title: Re: Xref 2 Block
Post by: T.Willey 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?
Title: Re: Xref 2 Block
Post by: GDF 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
Title: Re: Xref 2 Block
Post by: T.Willey 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)
)
Title: Re: Xref 2 Block
Post by: GDF 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
Title: Re: Xref 2 Block
Post by: T.Willey 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.
Title: Re: Xref 2 Block
Post by: GDF 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
Title: Re: Xref 2 Block
Post by: Greg B on January 18, 2006, 02:57:48 PM
Frank <the coworker> is 43 and he thanks you.


Sounds perfect for you Tim.
Title: Re: Xref 2 Block
Post by: T.Willey 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.
Title: Re: Xref 2 Block
Post by: Mark 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 ......
Title: Re: Xref 2 Block
Post by: LE 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?
Title: Re: Xref 2 Block
Post by: LE 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....
Title: Re: Xref 2 Block
Post by: Mark 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.
Title: Re: Xref 2 Block
Post by: T.Willey 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?
Title: Re: Xref 2 Block
Post by: Jeff_M 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 (http://www.theswamp.org/forum/index.php?topic=7496.0) The whole thread should be interesting reading for you.
Title: Re: Xref 2 Block
Post by: T.Willey on January 19, 2006, 10:44:09 AM
Thanks for the link Jeff.  I don't see anything that helps in this situation.  The only reason why I asked is because when updateding my plot routine, I had to release the plot configurations that I opened in the Odbx document to stop a crash that was pretty consistant.  I didn't crash after I ran the code posted here, so I figured it was okay, but I just wanted to make sure.
Title: Re: Xref 2 Block
Post by: GDF on January 19, 2006, 10:57:32 AM
Tim

Thanks for the XrefBlockInsert.lsp routine. My coworker has made another request. He wants to window select multiple xrefs <unit plans within a building>
and have them converted into one block. This is way out of my league, so I defer to you experts.

Gary
Title: Re: Xref 2 Block
Post by: T.Willey on January 19, 2006, 11:01:24 AM
I can't write it right now, but it shouldn't be too hard to change the lisp I provided.  Just use a selection set, make sure what is selected is an xref.  Make the block name, and the open each drawing with ObjectDBX and copy the objects into the new block.  Maybe change what I did into a sub-routine, and then just pass the xref, and the block name to it.  I think I would do that.

If no one writes one, then I will try when I have time.  How would you (co-worker) want the block named?
Title: Re: Xref 2 Block
Post by: GDF on January 19, 2006, 11:29:13 AM
Tim

Thanks. That vl stuff is beyond me. The block can be named something like "Footprint".

Gary
Title: Re: Xref 2 Block
Post by: LE on January 19, 2006, 11:37:12 AM
Master Tim while you are on the mood, I do not have the time to write any good code that could do ALL my interior elevations, I need for a house I am designing, it is a kind of complex, since is not just a boxy project... Hope you got time and willing to do it, I have a dead-line by the end of this month....


Sorry I could not resist.... He he....  :evil:  :evil:  :evil:
Title: Re: Xref 2 Block
Post by: GDF on January 19, 2006, 12:10:00 PM
Luis

I see the fruit does not fall far from the tree <your icon image>.
Title: Re: Xref 2 Block
Post by: T.Willey on January 19, 2006, 01:12:17 PM
Here you go.
Code: [Select]
(defun c:Xrefs2Block (/ ActDoc BlkCol LayCol Message NewBlkName ss Ent EntData BlkName BlkRefObj XrefList dbxApp
                        LayList ObjList FullPath NewBlk)

(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(setq BlkCol (vla-get-Blocks ActDoc))
(setq LayCol (vla-get-Layers ActDoc))
(setq Message "\n Enter block name: ")
(if
 (and
  (while
   (or
    (not NewBlkName)
    (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-Item (list BlkCol NewBlkName))))
   )
   (not (while (= (setq NewBlkName (getstring T Message)) "")))
   (setq Message "\n Block name already exist, please type another: ")
  )
  (setq ss (ssget '((0 . "INSERT"))))
 )
 (progn
  (while (setq Ent (ssname ss 0))
   (and
    (setq EntData (entget Ent))
    (setq BlkName (cdr (assoc 2 EntData)))
    (setq BlkRefObj (vla-item BlkCol BlkName))
    (= (vla-get-IsXref BlkRefObj) :vlax-true)
    (setq XrefList (cons Ent XrefList))
   )
   (ssdel Ent ss)
  )
  (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))
   )
  )
  (foreach Ename XrefList
   (setq BlkName (cdr (assoc 2 (entget Ename))))
   (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 (substr LayName (+ 2 (strlen BlkName))) LayList))
    )
   )
   (if (not NewBlk)
    (setq NewBlk (vlax-invoke BlkCol 'Add '(0.0 0.0 0.0) NewBlkName))
   )
   (if (setq FullPath (findfile (vla-get-Path (vlax-ename->vla-object Ename))))
    (progn
     (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 Can not find \"" FullPath "\" drawing to open."))
   )
   (setq LayList nil)
   (setq ObjList nil)
  )
  (vlax-release-object dbxApp)
  (setq dbxApp nil)
 )
)
(princ)
)
This works on my test drawing.  If the xref's are rotated or scaled, then it won't correct that.  No error trapping either.

Master Tim <snip>

This just makes me want to try and figure out a code.  :roll:
Title: Re: Xref 2 Block
Post by: LE on January 19, 2006, 01:14:56 PM
This just makes me want to try and figure out a code.  :roll:

No.... I don't need nothing.... thanks....  :kewl:
Title: Re: Xref 2 Block
Post by: T.Willey on January 19, 2006, 01:50:59 PM
No.... I don't need nothing.... thanks.... :kewl:
I know, you are WAY better than I am at code anyway, but the challenge would be fun.
Title: Re: Xref 2 Block
Post by: LE on January 19, 2006, 02:00:47 PM
I know, you are WAY better than I am at code anyway, but the challenge would be fun.

Hey.... there is only one person in the world, that really knows everything.... the name is unnamed.....

Actually... to do block-outs it would be very easy.... have no idea of how many will benefit of such routine... in my case, I have to come up with all interior elevations for the type of projects I have to do....
Title: Re: Xref 2 Block
Post by: Jeff_M on January 19, 2006, 06:25:07 PM
Hey Tim, your routines for the xref to block look good, except I notice that if there is anything drawn on Layers 0 or Defpoints in the xref they do not get copied.........note that there is never a layer called XRName|0 or XRName|Defpoints ?

I thought I'd also mention that I couldn't figure out why your attempt at using the XRDatabase failed. Then I tried & tried & tried and finally realized that the XRDB has the Xref layers already. SO it appears you can do a lot of things with the XRDB, copyobjects to another owner is not one of them since you cannot place items on an Xref layer.
Title: Re: Xref 2 Block
Post by: T.Willey on January 19, 2006, 06:46:18 PM
Hey Tim, your routines for the xref to block look good, except I notice that if there is anything drawn on Layers 0 or Defpoints in the xref they do not get copied.........note that there is never a layer called XRName|0 or XRName|Defpoints ?
Good point.  I didn't even think about those two layers. Thanks.  This should be an easy fix if it's wanted.

I thought I'd also mention that I couldn't figure out why your attempt at using the XRDatabase failed. Then I tried & tried & tried and finally realized that the XRDB has the Xref layers already. SO it appears you can do a lot of things with the XRDB, copyobjects to another owner is not one of them since you cannot place items on an Xref layer.
Yea.  I was thinking that maybe you cuold change the layer before copying, but then I said no way, that wouldn't work.  So I decided to go the ObjectDBX route.

Now that you mention things about layers, I wonder if I should run through the list when I first open the drawing, and unlock all the layers, or does that matter with ObjectDBX?  I don't think I have run into this issue, but I don't lock layers, so I wouldn't, but if someone knows the please post.
Title: Re: Xref 2 Block
Post by: T.Willey on January 19, 2006, 07:16:14 PM
Now that you mention things about layers, I wonder if I should run through the list when I first open the drawing, and unlock all the layers, or does that matter with ObjectDBX? I don't think I have run into this issue, but I don't lock layers, so I wouldn't, but if someone knows the please post.
In my testing, it doesn't matter.  If the layer is locked, it will bring it over locked.  I ran it again after it brought in the locked layer, and it still shows like it should.  That is cool.
Title: Re: Xref 2 Block
Post by: GDF on January 20, 2006, 10:25:38 AM
Tim

Thanks for your time and routine for addressing my question. I really do thank you.

We do mostly tax credit low income housing <like appartments> here at our office. We xref the unit plans into the building plan. A typical building plan can have multiple units of the same type, often mirrored and rotated. The request was based upon the need to simplify the process of doing an xref bind insert with a minimum of layers turned on. This new block would be used for the site plan.

I thought that others along with our inhouse use could benefit from a routine that could make a block out of all xrefs selected with only the current layers visible used.
Your latest routine only captured three of the ten unit plans within the xref. Also the new block does not match the rotation or mirrored state found in the xref.

I am going to have to learn this vl lisp stuff when I get the time. Anyway thanks for taking the time on this request. This is still an open request if anyone is up to the challange. This is way beyond my meger lisp knowledge.

Maybe Luis will come up with an arx function to do the trick. He He.

Anyway for not we will just have to do the bind insert option.

Gary
Title: Re: Xref 2 Block
Post by: T.Willey on January 20, 2006, 11:13:21 AM
One would have to know about Matrices, and I do not.  I looked into them a little, but didn't get what I felt was a good enough understanding of how to use them/ make them.  I want to learn this, just because I think it would be fun, so if anyone has a link to a good Matrix explanation, please post.

Your latest routine only captured three of the ten unit plans within the xref.
You saying that you picked 10 xrefs, and only three were returned?  That is not right.  Are any of them nested?  I don't know how it will handel nested ones.

If I get somemore free time, I will see what I can do.
Title: Re: Xref 2 Block
Post by: GDF on January 20, 2006, 11:42:58 AM
Thanks Tim

Here is some matrix functions....I think.

Gary
Title: Re: Xref 2 Block
Post by: Joe Burke on January 21, 2006, 05:22:58 AM
Tim and Jeff,

I've seen cases where CopyObjects with the XRDB as the source failed randomly. Well, at least as far as I could tell.

I also recall a topic in the Autodesk NG by James Allen where he reported the same thing. The conclusion there was why bother.
Title: Re: Xref 2 Block
Post by: Joe Burke on January 21, 2006, 06:00:01 AM
Hi Gary,

I revised those functions since what you posted. Here's the latest set. The revisions correct a bug when a block's Normal is (0 0 -1).
Title: Re: Xref 2 Block
Post by: CAB on January 21, 2006, 08:52:57 AM
Joe,
Thanks for the update. :-)
Title: Re: Xref 2 Block
Post by: GDF on January 21, 2006, 03:18:19 PM
Thanks Joe for the update.

Code: [Select]
I revised those functions since what you posted. Here's the latest set. The revisions correct a bug when a block's Normal is (0 0 -1).

Gary
Title: Re: Xref 2 Block
Post by: CADaver on January 21, 2006, 09:53:29 PM
Have you used already the "terminator" ? ...

whatever for??

how do you like the nested copy ?....

one of the two things i like about msta (the other is dim strings)

the what you see, what you get thing...

not even close to WYSIWYG linetypes, fonts, and lineweights.  you have no clue what the lkinetypes look like until you plot it. ignorant piece of software.

much better than acad no?

in a word, no.
Title: Re: Xref 2 Block
Post by: T.Willey on January 23, 2006, 11:34:07 AM
Hey Joe,

  Thanks for the Matrix codes.  I have been working one some (trying to understand them) and I came up with the same rotation calculations that you did, and they both don't seem to work correctly.  Maybe I'm using them wrong I don't know.  What I'm doing here is:

I get all the objects from the selected xref.
I copy them into the current drawing, into a new block definition.
I then apply the functions you provided to the xref selected.
I then apply the returned matrix to each object.
I then insert the block, hoping that it matches what is on the screen now
but the rotation is wrong, but the scaling is right.

What am I doing wrong?
Thanks in advance.
Title: Re: Xref 2 Block
Post by: CAB on January 23, 2006, 11:58:29 AM
Tim,
You guys are way ahead of me so this may be off base.
But using the nentsel matrix results in a rotation in the wrong direction
where nentselp matrix gives the rotation in the correct direction.
Title: Re: Xref 2 Block
Post by: T.Willey on January 23, 2006, 12:06:40 PM
Tim,
You guys are way ahead of me so this may be off base.
But using the nentsel matrix results in a rotation in the wrong direction
where nentselp matrix gives the rotation in the correct direction.

I guess I could try and use that, but with the new way Gary wants it to work is more like a selection set, so I was trying to create the matrix off the object itself.  I guess I could have it go until enter is pressed, and just use either nentsel, or nentselp.  I guess this is kind of a learning chance for me, so I was hoping to learn how to do matrices with this routine.
Thanks for the info Alan.

ps.  That is really weird to me, that only one would be correct.
Title: Re: Xref 2 Block
Post by: CAB on January 23, 2006, 12:08:26 PM
I was working on placing a rectangle around nested text which could be
scaled within nested blocks & rotated. I has worked in my testing but
who knows if all combinations of situations will work.
http://www.theswamp.org/forum/index.php?topic=7003.msg107478#msg107478
Title: Re: Xref 2 Block
Post by: T.Willey on January 23, 2006, 12:22:26 PM
I was working on placing a rectangle around nested text which could be
scaled within nested blocks & rotated. I has worked in my testing but
who knows if all combinations of situations will work.
http://www.theswamp.org/forum/index.php?topic=7003.msg107478#msg107478
That is a lot of code to digest.  I will try and understand it all when I get a chance.

I would really prefer to get the matrix from the object, and not have to use either "nentsel/p" options.  But if I have to, then I have to.  We shall see.

Thanks again.
Title: Re: Xref 2 Block
Post by: GDF on January 23, 2006, 12:32:38 PM
Thanks Tim, Allen, Jeff and everyone else for attacking this request. This stuff is way beyond my ability.

Gary
Title: Re: Xref 2 Block
Post by: T.Willey on January 23, 2006, 12:33:54 PM
Thanks Tim, Allen, Jeff and everyone else for attacking this request. This stuff is way beyond my ability.

Gary
Mine too, but I love a challenge, and the learning it brings.  :evil:
Title: Re: Xref 2 Block
Post by: T.Willey on January 23, 2006, 01:27:18 PM
Here is one that works.  Be careful and test it first.  My setup here seems to crash when I use the xref command after, but not when I use ".xref", so I'm thinking it is something with my Acad setup.  Let me know what happens.
What I fixed was soemthing I saw in a code by Joe Burke.  When he got the answer (matrix) from the function "ObjMatrix" he turned it into a variant, and then passed the variant to (vla-transformedby.... , and that seemed to work here also.  Make sure you have the lisps that he provided loaded, or it will error.

Thanks Joe.
Code: [Select]
(defun c:Xrefs2Block (/ ActDoc BlkCol LayCol Message NewBlkName ss Ent EntData BlkName BlkRefObj XrefList dbxApp
                        LayList ObjList FullPath NewBlk NewObjList LayToLock XrefObj)

(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(setq BlkCol (vla-get-Blocks ActDoc))
(setq LayCol (vla-get-Layers ActDoc))
(setq Message "\n Enter block name: ")
(if
(and
  (while
   (or
    (not NewBlkName)
    (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-Item (list BlkCol NewBlkName))))
   )
   (not (while (= (setq NewBlkName (getstring T Message)) "")))
   (setq Message "\n Block name already exist, please type another: ")
  )
  (setq ss (ssget '((0 . "INSERT"))))
)
(progn
  (while (setq Ent (ssname ss 0))
   (and
    (setq EntData (entget Ent))
    (setq BlkName (cdr (assoc 2 EntData)))
    (setq BlkRefObj (vla-item BlkCol BlkName))
    (= (vla-get-IsXref BlkRefObj) :vlax-true)
    (setq XrefList (cons Ent XrefList))
   )
   (ssdel Ent ss)
  )
  (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))
   )
  )
  (foreach Ename XrefList
   (setq BlkName (cdr (assoc 2 (entget Ename))))
   (setq XrefObj (vlax-ename->vla-object Ename))
   (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 (substr LayName (+ 2 (strlen BlkName))) LayList))
    )
   )
   (if (not NewBlk)
    (setq NewBlk (vlax-invoke BlkCol 'Add '(0.0 0.0 0.0) NewBlkName))
   )
   (if (setq FullPath (findfile (vla-get-Path XrefObj)))
    (progn
     (vla-Open dbxApp FullPath)
     (vlax-for i (vla-get-ModelSpace dbxApp)
      (if (vl-position (vla-get-Layer i) LayList)
       (setq ObjList (cons i ObjList))
      )
     )
     (setq NewObjList (vlax-invoke dbxApp 'CopyObjects ObjList NewBlk))
     (foreach Lay LayList
      (if
       (and
        (not (vl-catch-all-error-p (setq LayObj (vl-catch-all-apply 'vla-Item (list LayCol Lay)))))
        (= (vla-get-Lock LayObj) ':vlax-true)
       )
       (progn
        (vla-put-Lock LayObj :vlax-false)
        (setq LayToLock (cons LayObj LayToLock))
       )
      )
     )
     (foreach i NewObjList
      (vla-TransformBy i (vlax-tmatrix (ObjMatrix XrefObj)))
     )
     (mapcar 'vlax-release-object NewObjList)
     (vlax-release-object XrefObj)
     (setq NewObjList nil)
     (foreach Lay LayToLock
      (vla-put-Lock  Lay :vlax-true)
     )
     (setq LayToLock nil)
    )
    (prompt (strcat "\n Can not find \"" FullPath "\" drawing to open."))
   )
   (setq LayList nil)
   (setq ObjList nil)
  )
  (if NewBlk
   (vlax-invoke (vla-get-Block (vla-get-ActiveLayout ActDoc)) 'InsertBlock '(0.0 0.0 0.0) (vla-get-Name NewBlk) 1.0 1.0 1.0 0.0)
  )
  (vlax-release-object dbxApp)
  (setq dbxApp nil)
)
)
(princ)
)

ps.  Forgot to tell you, this will insert the block also.
Title: Re: Xref 2 Block
Post by: GDF on January 23, 2006, 02:12:26 PM
Thanks Tim

; error: no function definition: OBJMATRIX

Gary
Title: Re: Xref 2 Block
Post by: T.Willey on January 23, 2006, 02:15:57 PM
Thanks Tim

; error: no function definition: OBJMATRIX

Gary

What I fixed was soemthing I saw in a code by Joe Burke.  When he got the answer (matrix) from the function "ObjMatrix" he turned it into a variant, and then passed the variant to (vla-transformedby.... , and that seemed to work here also.  Make sure you have the lisps that he provided loaded, or it will error.
Title: Re: Xref 2 Block
Post by: GDF on January 23, 2006, 02:24:52 PM
Thanks Tim

I found the function from the previous post.

WORKS GREAT.

Thank You....and my coworker thanks you.

Gary
Title: Re: Xref 2 Block
Post by: T.Willey on January 23, 2006, 02:29:03 PM
So you didn't have any problems after running it?  Your CAD didn't crash?
That is cool.  My setup here is a little weird, but that is how the company wants it.  Glad it works for you.

You're welcome, and so is Frank.
Title: Re: Xref 2 Block
Post by: GDF on January 23, 2006, 02:44:09 PM
Tim

Works great in 2006, with no problems. I will add a warning and instruction message to display before the routine is run.

WOW this is great. We will be using this all of the time now. Thank you.

Gary
Title: Re: Xref 2 Block
Post by: GDF on January 23, 2006, 02:48:36 PM
Sorry, I forgot to thank Joe Burke for his help.

Gary <with a big smile on my face>.
Title: Re: Xref 2 Block
Post by: Joe Burke on January 24, 2006, 04:12:40 AM
Hey Joe,

  Thanks for the Matrix codes.  I have been working one some (trying to understand them) and I came up with the same rotation calculations that you did, and they both don't seem to work correctly.  Maybe I'm using them wrong I don't know.  What I'm doing here is:

I get all the objects from the selected xref.
I copy them into the current drawing, into a new block definition.
I then apply the functions you provided to the xref selected.
I then apply the returned matrix to each object.
I then insert the block, hoping that it matches what is on the screen now
but the rotation is wrong, but the scaling is right.

What am I doing wrong?
Thanks in advance.

Hi Tim,

I'm replying to the above and your later message after you found the solution.

I don't understand. Are you saying you did not get an error when the vlax-tmatirx function was not included? Just that the result was incorrect? if so, that is strange. I would expect TransformBy to choke without the conversion vlax-tmatrix does.

Were you doing this: (vlax-invoke obj 'TransformBy <raw matrix>)? I haven't tried it. I guess there's a chance TransformBy, called that way, might accept that.
Title: Re: Xref 2 Block
Post by: Joe Burke on January 24, 2006, 04:13:52 AM
Sorry, I forgot to thank Joe Burke for his help.

Gary <with a big smile on my face>.

Gary,

My pleasure.
Title: Re: Xref 2 Block
Post by: T.Willey on January 24, 2006, 11:03:30 AM
I don't understand. Are you saying you did not get an error when the vlax-tmatirx function was not included? Just that the result was incorrect? if so, that is strange. I would expect TransformBy to choke without the conversion vlax-tmatrix does.

Were you doing this: (vlax-invoke obj 'TransformBy <raw matrix>)? I haven't tried it. I guess there's a chance TransformBy, called that way, might accept that.

I got no error when (vlax-invoke obj 'TransformBy <matrix list <of list>>).  It would rotate, but it would rotate the wrong way.  Not sure why that happened, but switching to (vla-TransformBy obj (vlax-tmatrix <matrix list <of list>>)) worked.

Thanks again for the codes Joe.