Insert External Reference to Each Layout

Insert External Reference to Each Layout

Anonymous
Not applicable
623 Views
2 Replies
Message 1 of 3

Insert External Reference to Each Layout

Anonymous
Not applicable

Hello everybody,

I have problem with insertion of external reference to each layouts.

Below is the some part of my code and a sub function EXREFEKLE in which i want to add an external reference to each layout.

In the code i can obtain EBATK amount of layouts but my external reference is exisiting only at the first layout.

Best regards

....

Call EXREFEKLE(ka1K, olc2K, EBATK)

.....

 

 

Public Sub EXREFEKLE(ka1K, olc2K, EBATK)
ThisDrawing.ActiveSpace = acPaperSpace
Dim xrefInsertedK As AcadExternalReference
Dim LayoutsK As AcadLayouts          
Dim bnoK(0 To 2) As Double
 
Dim STRPATH1K As String
Dim STRPATH2K As String
Dim STRNAME1K As String
Dim STRNAME2K As String
 
bnoK(0) = 0
bnoK(1) = 0
 
STRPATH1K = "D:\MYFOLDER\" & ka1K
STRNAME1K = "TEST"
 
With ThisDrawing.Utility
For j = 1 To PaftaSay
ThisDrawing.Layouts.Add EBATK & j   
Next j
Set LayoutsK = ThisDrawing.Layouts 
LayoutsK("Layout1").Delete    ' ok
LayoutsK("Layout2").Delete   ' ok
End With
 
Set xrefInsertedK = ThisDrawing.PaperSpace.AttachExternalReference(STRPATH1K, STRNAME1K, bnoK, olc2K, olc2K, olc2K, 0, False)
 

End Sub
0 Likes
Accepted solutions (1)
624 Views
2 Replies
Replies (2)
Message 2 of 3

norman.yuan
Mentor
Mentor
Accepted solution

You only insert the Xref once (into the currently active layout), how could expect the Xref to be in all newly created layouts?

 

ThisDrawing.PaperSpace.AttachExternalReference() only attach a file as Xref to active layout (PaperSpace). Since your code create multiple layouts, you need to make sure to set each new layout as active Layout and attach Xref. Something like:

 

Option Explicit

Public Sub InserXref()

    Dim lay As AcadLayout
    Dim i As Integer
    Dim xrefFile As String
    Dim xref As AcadExternalReference
    Dim pt(0 To 2) As Double
    
    xrefFile = "E:\Temp\TestXref.dwg"
    pt(0) = 0#: pt(1) = 0#: pt(2) = 0#
    
    ThisDrawing.ActiveSpace = acPaperSpace

    For i = 1 To 3
        Set lay = ThisDrawing.Layouts.Add("TestLayout" & i)
        ThisDrawing.ActiveLayout = lay
        Set xref = ThisDrawing.PaperSpace.AttachExternalReference( _
            xrefFile, "TestXref", pt, 1#, 1#, 1#, 0#, False)
        xref.Update
    Next
    
End Sub

HTH

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 3

Anonymous
Not applicable

Thank you Norman,

This is what i am looking for.

Regards

0 Likes