TheSwamp

Code Red => VB(A) => Topic started by: cadpro on July 13, 2008, 03:23:25 AM

Title: xref in model or paper space?
Post by: cadpro on July 13, 2008, 03:23:25 AM
Hi,

How can I find out in vba if xref is inserted in model space or paper space?

Thanks
Title: Re: xref in model or paper space?
Post by: fixo on July 13, 2008, 05:59:33 AM
Guess you need check the 'OwnerID' of xref,
then get the owner with the help of
'ObjectIdToObject' function

~'J'~
Title: Re: xref in model or paper space?
Post by: CadRover on July 21, 2008, 03:42:27 AM

Cadpro

Couldn't you tell by just looking?
Perhaps in the xref manager?

Is there something specific that you are trying to do?

Cadr
Title: Re: xref in model or paper space?
Post by: Bob Wahr on July 23, 2008, 01:13:28 PM
How is the xref being selected?
Title: Re: xref in model or paper space?
Post by: cadpro on July 24, 2008, 04:03:19 AM
I'm trying to change the color of all xrefs in a drawing, except for the xrefs inserted into paper space.

Thanks
Title: Re: xref in model or paper space?
Post by: fixo on July 24, 2008, 07:18:18 AM
Not sure about it will works correct
Just was written blindly without editor
so you need to test it extensively

Code: [Select]
Sub ChXrefColor()

Dim oEnt As AcadEntity
Dim oXRef As AcadExternalReference
Dim i As Integer
Dim col As Integer
col = CInt(InputBox(vbCrLf & "Enter color number <1-255> : ", "XRef Color", 121))
For Each oEnt In ThisDrawing.ModelSpace
If TypeOf oEnt Is AcadExternalReference Then
Set oXRef = oEnt
oXRef.color = col
End If
Next

End Sub

~'J'~
Title: Re: xref in model or paper space?
Post by: Bob Wahr on July 24, 2008, 10:50:47 AM
That's pretty much what I was thinking.  If you are dealing with really huge drawings, you could do a filtered selection set to select the modelspace xrefs but for normal sized drawings, there shouldn't be much of a performance knock doing it that way.  If you are needing to change the layer colors in that xrefs, you can use the oxref's name and loop through the layers.
Title: Re: xref in model or paper space?
Post by: cadpro on October 27, 2008, 04:20:19 AM
That didn't work! I doesn't change the xref layer color.
Title: Re: xref in model or paper space?
Post by: Bob Wahr on October 27, 2008, 12:28:57 PM
Since it's pretty obvious that you are in a big hurry for it, I'll add some more.  Just typing it in this window so it'll probably need some tweaking.

Code: [Select]
Sub ChXrefColor()

Dim oEnt As AcadEntity
Dim oXRef As AcadExternalReference
Dim i As Integer
Dim col As Integer
Dim oLays as acadlayers
dim oLay as acadlayer
dim sLay as string
set olays as thisdrawing.layers
col = CInt(InputBox(vbCrLf & "Enter color number <1-255> : ", "XRef Color", 121))
For Each oEnt In ThisDrawing.ModelSpace
If TypeOf oEnt Is AcadExternalReference Then
Set oXRef = oEnt
for each olay in olays
if left(olay.name, len(oxref.name)) = oxref.name then
olay.color = col
end if
next olay
End If
Next oent

End Sub
Title: Re: xref in model or paper space?
Post by: Bob Wahr on October 27, 2008, 12:33:29 PM
Actually, that probably needs to be set as truecolor, not color.
Title: Re: xref in model or paper space?
Post by: cadpro on October 28, 2008, 12:37:41 AM
Thank you sooooooo much! You are great!

Oh wait! I'm sorry to tell you that unfortunately it doesn't change the layer color of nested xrefs. Is there any solution to that?

Thanks
Title: Re: xref in model or paper space?
Post by: Daniel J. Ellis on October 28, 2008, 03:22:34 AM
Why do you need to?  I didn't think the layer colour of xrefs actually did anything.
Title: Re: xref in model or paper space?
Post by: Bob Wahr on October 28, 2008, 01:28:10 PM
Here's some stuff from a thingy.  The code as it is here is used to get paths of xrefs, but shows a method for drilling in looking for nested xrefs.  Let me know if you need help putting it together.

Code: [Select]
Private Sub LoadXrefs()
  Dim objSelSets As AcadSelectionSets
  Dim objSelSet As AcadSelectionSet
  Dim intType(0) As Integer
  Dim varData(0) As Variant
  Dim strPaths() As String
  Dim intCnt As Integer
  Dim objXref As AcadExternalReference
  Dim objEnt As AcadEntity
  Dim objBlk As AcadBlock
  Dim objBlks As AcadBlocks
  Dim intDuplicate As Integer
  Dim objDuplicate As AcadEntity
  Dim boolDuplicate As Boolean
 
  Set objBlks = ThisDrawing.Blocks
  Set objSelSets = ThisDrawing.SelectionSets
  For Each objSelSet In objSelSets
    If objSelSet.Name = "GetXrefPaths" Then
      objSelSets.Item("GetXrefPaths").Delete
      Exit For
    End If
  Next
  Set objSelSet = objSelSets.Add("GetXrefPaths")
  intType(0) = 0: varData(0) = "INSERT"
  objSelSet.Select acSelectionSetAll, , , intType, varData
  For Each objEnt In objSelSet
    Set objBlk = objBlks(objEnt.Name)
    If objBlk.IsXRef Then
      boolDuplicate = False
      For intDuplicate = 1 To colXrefs.Count
        Set objDuplicate = colXrefs.Item(intDuplicate)
        If objDuplicate.Name = objEnt.Name Then
          boolDuplicate = True
          Exit For
        End If
      Next intDuplicate
      If boolDuplicate = False Then
        colXrefs.Add objEnt '.Path
        GetNested objBlk
      End If
    End If
  Next objEnt

End Sub

Private Function GetNested(objBlk As AcadBlock) As Integer
  Dim objXref As AcadExternalReference
  Dim objBlkRef As AcadBlockReference
  Dim objEnt As AcadEntity
  Dim objNext As AcadBlock
    For Each objEnt In objBlk
      If TypeOf objEnt Is AcadBlockReference Then
        Set objBlkRef = objEnt
        Set objNext = ThisDrawing.Blocks(objBlkRef.Name)
        If objNext.IsXRef Then
          Set objXref = objEnt
          colXrefs.Add objXref
          GetNested objNext
        End If
      End If
    Next
  GetNested = colXrefs.Count
End Function
Haven't really looked at that code in a good while.  I have no idea why GetNested is a function instead of a sub.

Danellis, changing xref layers changes the appearance of the objects on those layers, as long as the color/lt are set to bylayer.  The same as any other object on any other layer.
Title: Re: xref in model or paper space?
Post by: cadpro on October 30, 2008, 02:45:25 AM
What could be colXrefs?
Title: Re: xref in model or paper space?
Post by: Bob Wahr on October 30, 2008, 11:04:09 AM
In this case colxrefs is a collection declared publicly
Title: Re: xref in model or paper space?
Post by: Bob Wahr on October 30, 2008, 11:05:34 AM
You wouldn't ever have to add the xrefs to a collection though, just go through looking for nested xrefs, if found change layer properties.