Author Topic: Xref multiple times with one dwg file  (Read 8456 times)

0 Members and 1 Guest are viewing this topic.

Jeff H

  • Needs a day job
  • Posts: 6144
Re: Xref multiple times with one dwg file
« Reply #30 on: November 22, 2011, 04:36:18 PM »
Got it loaded up and can read it easier in VS
Could you load a test drawing with some of blocks?

TJK44

  • Guest
Re: Xref multiple times with one dwg file
« Reply #31 on: November 22, 2011, 04:43:54 PM »
Here is the same one that I took a screen shot of earlier.


Jeff H

  • Needs a day job
  • Posts: 6144
Re: Xref multiple times with one dwg file
« Reply #32 on: November 22, 2011, 07:35:21 PM »
Sorry got tied up and need to go but will have time tomorrow to post more.
 
I at least see what the problem is.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Xref multiple times with one dwg file
« Reply #33 on: November 22, 2011, 08:05:39 PM »
Jeff,
I've waiting for 4 1/2 days for an accurate, concise, relevant  description of the problem issues from the OP in one post ... care to share ??

added:

No hurry ... I'm just being a pedant :)
Regards
« Last Edit: November 22, 2011, 11:45:37 PM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Jeff H

  • Needs a day job
  • Posts: 6144
Re: Xref multiple times with one dwg file
« Reply #34 on: November 22, 2011, 11:38:12 PM »
Sorry about that I had someone come in the office and need some things and then had to run out to get my son.
 
I am staying at relatives house tonight to help get son to sleep and get him up because he is going to ride with them....... that does not matter but have no info, VS, AutoCAD, etc.... in front of me. So this is coming from where ever I can pull it out.
 
-The first obvious thing is to break up the function because it is just too much to 
  try to focus on at once. There are 4, 10 or however many databases, 
  transactions to keep up with.
 
 
 
-You are Wblocking the BlockReference. So you are creating a file that contains a
  'insert' inserted at the same position.
 
Quote
If it has a different attribute (partnumber) it is fine, the problem comes in when there are multiples of the same part(block). In this case each block will be a part in the drawing

-You are using the PartNumber as the unique identifier. The only thing that
  differentiates a xref from one another is the part number
 
-When a BlockReference with the same BlockDefinition have different values for
  the part numbers a new file to xref is created. You are creating files to xref based
  on the part number.
 
-Maybe you want a different 'xref' for each 'Part Number' but you are naming your 
 files and xref blockTableRecord with the textstring value of the AttributeReference.
 If they have the same part number than they will come from last created file to  xref, same block  or not.
 Give them all the same part number and see what happens.
 It just keeps overwriting itself. Still not clear but would make more sense to me to 
 use block name
 
If I use this code it will bring all the blocks in as xref's each referencing the correct drawing but their positions are way off.

Code: [Select]
Dim bref As New BlockReference(Point3d.Origin, xrefObjId)
Dim scale As Scale3d = blkRef.ScaleFactors
bref.Position = blkRef.Position



First you set postion at the orgin then you change to the BlockReference's Position.
 
Again the reason it is off is because you create a file with a 'insert' at say (10,10) where it belongs. Then you xref it that and insert it a (10,10) so now it is at (20,20)
 
When you use Point3d.Origin the reason they are on top of each other is the same reason as explained above. If they have the same PartNumber they are Defined from the same definition which is the last file added with that part number.
 
So when you have multiple blockreferences and do NOT want a different xref for each insert I think it creates too much complexity creating the files to be xrefed with a BlockReference.
Which one do you choose?
Have to transform all the others.
etc....
 
 
There is probably better methods or to avoid it all together but if needed the first thing that comes to mind is wblock the definition so each entity is the same distance from the xref file orgin as it was in the definition. That way the Blcokreference insertion point could be used.
 
Use the BlockName as identifier so that way you could do something like
 
XrefID
 
If bt.Has("BlockName") then
XrefID = bt("BlockName")
Else
XrefID = db.AttachXref.......
End If
 
Blockref = new Blockreference(pnt, XrefID )
 
 
 
Sorry I am in hurry and hope that helps but tommorrow will be able to post something that maybe makes more sense.
 
 
 

kaefer

  • Guest
Re: Xref multiple times with one dwg file
« Reply #35 on: November 23, 2011, 05:40:39 AM »
@Jeff H: Congratulations for your promotion!
@TJK44: Okay, here I'm at it again, still not according to your spec (but close, hopefully).

In the source drawing, collect the ObjectIds of the BlockReferences and their names.
Code: [Select]
        Dim xNames = New List(Of String)()
        Dim oidc = New ObjectIdCollection()
        ' Collect BlockReferences and Xref names
        Using tr As Transaction = db.TransactionManager.StartTransaction()
            For Each br In
            From bref In SymbolUtilityServices.GetBlockModelSpaceId(db).GetObject(Of BlockTableRecord)().GetObjects(Of BlockReference)()
            Where
                bref.AttributeCollection.GetObjects(Of AttributeReference)() _
                .FirstOrDefault(Function(attref) attref.Tag.Equals("Part Number", StringComparison.InvariantCultureIgnoreCase)) _
                IsNot Nothing AndAlso _
                targetFiles.Contains(bref.Name, StringComparer.InvariantCultureIgnoreCase)
            Select bref
                oidc.Add(br.ObjectId)
                If Not xNames.Contains(br.Name, StringComparer.InvariantCultureIgnoreCase) Then
                    xNames.Add(br.Name)
                End If
            Next
            tr.Commit()
        End Using

Then create a side database, where the Xrefs are attached (or overlayed). After that, using WBlockCloneObjects with DuplicateRecordCloning.Ignore, I'll transfer the BlockReferences collected in the previous step. Voila, they're instances of external refences. Only thing to do is to remove their attributes, and to save the whole thing.

Code: [Select]
        Using destDb = New Database(True, True),
            destTr = destDb.TransactionManager.StartTransaction()
            For Each xName In xNames
                destDb.OverlayXref(System.IO.Path.Combine(targetDir, xName), xName)
            Next
            Dim msId = SymbolUtilityServices.GetBlockModelSpaceId(destDb)
            destDb.WblockCloneObjects(oidc, msId, New IdMapping(), DuplicateRecordCloning.Ignore, False)

Complete code attached.

TJK44

  • Guest
Re: Xref multiple times with one dwg file
« Reply #36 on: November 23, 2011, 08:14:10 AM »
I'm trying to download the complete code you posted kaefer to take a look at it, for some reason everytime I click the link (or any link) it prompts me to download index.php and I can never download the file.

*Resolved - used IE instead of Firefox

TJK44

  • Guest
Re: Xref multiple times with one dwg file
« Reply #37 on: November 30, 2011, 11:27:01 AM »
I found a way to get the xrefs to show in the correct positions. If the original block has a position of 0,0,0 and then I xref it using this code it works. The only problem with this is the user can not pick an insertion point for the block. I'll keep working on it when I have the time and report back.

Code: [Select]
Dim bref As New BlockReference(blkRef.Position, xrefObjId)
bref.Rotation = blkref.Rotation
bref.ScaleFactors = blkref.ScaleFactors