Selecting Object not inside an External reference.

Selecting Object not inside an External reference.

pranieriADNKG
Explorer Explorer
729 Views
7 Replies
Message 1 of 8

Selecting Object not inside an External reference.

pranieriADNKG
Explorer
Explorer

Hi to Everybody,

I'm trying to replace a text with another inside a drawing which is containing external reference drawing (not a block).

The main issue concern that a text object will be found but not in the modelspace area but only in external reference and none of text type object outside external reference object will be found.

For Each MyEnt In ThisDrawing.ModelSpace
    If TypeOf MyEnt Is AcadText Then
        If InStr(1, MyEnt.TextString, "SWITCH") > 0 Then
            MyEnt.TextString = "SWITCH HOUSE SH-18"
        End If
    End If
Next

Here a part of the code for finding text.

In order to check if the required text to replace it's really a text object type I tried with the code below selecting "by pointing" the text to be changed, and it's working fine.

Sub Testing()
Dim MyEnt As Object
Dim MyPoint As Variant
ThisDrawing.Utility.GetEntity MyEnt, MyPoint
If InStr(1, MyEnt.TextString, "SWITCH") > 0 Then
    MyEnt.TextString = "SWITCH HOUSE SH-18"
End If
End Sub

 

Thank you for your help. 

0 Likes
730 Views
7 Replies
Replies (7)
Message 2 of 8

Ed__Jobe
Mentor
Mentor

You didn't ask a question. What is your problem? Are you wanting to make sure that no text in the xref will be selected? If so, remember that your code only works on ThisDrawing.Modelspace. When that runs, it will find the xref as an AcadReference object. You would have to specifically find the corresponding block and iterate it's contents to find any additional subentities. So the answer is that no, your code would not find text inside a block or an xref.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 3 of 8

grobnik
Collaborator
Collaborator

Hi @Ed__Jobe the question is why I'm not able to find the required text in model space with the code.

The text as I explained in the post above, it's part of drawing Model area, what found in ext reference it's not matching with the text to search.

Is there a way to exclude from the search those drawn in external  reference objects ?

Seems very strange, I'll try to deattach the ext refence and repeat the test.

Thank you.

0 Likes
Message 4 of 8

Ed__Jobe
Mentor
Mentor

@grobnik Are you also posting as @pranieriADNKG ?

 

I'm still not certain which text you want to isolate. Are you wanting to change only text in the xref or only text in the parent drawing's model space? The two code samples you show work totally different from each other.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 5 of 8

grobnik
Collaborator
Collaborator

 @Ed__Jobe I start the post with work account, later used "home" account this is the reason of two diffent users.

In any case text to isolate it's in the modelspace area, the only text found by code it's into External refernce part not wanted, even if text to be replaced it's available and drawn in Model Space.

Please note that inside the modelspace area there are other text too which are not trapped by the procedure.

Seem to be something which I'm missing, I checked the text, I check the drawing.

If you have some suggestion could be appreciated.

Unfortunately I cannot exchange the source dwg.

0 Likes
Message 6 of 8

Ed__Jobe
Mentor
Mentor

The second sample is impractical, so let's ignore it. The first example will find text only in Modelspace of ThisDrawing, and will not find text in an xref. Is this not what you want? I added a text "SWITCH" to modelspace of a new dwg and the sample code changed it. Do you want it to also find text in the xref? If you want to modify the xref, then the following sample works for me.

Sub grobnik1()
    Dim MyEnt1 As AcadEntity
    Dim MyEnt2 As AcadEntity
    For Each MyEnt1 In ThisDrawing.ModelSpace
        If TypeOf MyEnt1 Is AcadBlockReference Then
            Dim br As AcadBlockReference
            Dim blk As AcadBlock
            Set br = MyEnt1
            Set blk = ThisDrawing.Blocks(br.Name)
            If blk.IsXRef Then
                Dim i As Integer
                For i = 0 To blk.Count - 1
                    Set MyEnt2 = blk.item(i)
                    If TypeOf MyEnt2 Is AcadText Then
                        If InStr(1, MyEnt2.TextString, "SWITCH") > 0 Then
                            MyEnt2.TextString = "SWITCH HOUSE SH-18"
                        End If
                    End If
                Next i
                ThisDrawing.Regen acAllViewports
            End If
        End If
    Next
End Sub

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 7 of 8

pranieriADNKG
Explorer
Explorer

Hi @Ed__Jobe I'll try thank yout for the support, but just a question about the external ref it's not a block reference, it will be managed the same as a block reference ?.

Thank you.

0 Likes
Message 8 of 8

Ed__Jobe
Mentor
Mentor

@pranieriADNKG wrote:

Hi @Ed__Jobe I'll try thank yout for the support, but just a question about the external ref it's not a block reference, it will be managed the same as a block reference ?.

Thank you.


When you create a block, it's definition is stored in the Blocks table. When you insert an xref, AutoCAD reads the contents of that drawing's modelspace and creates an entry in the Blocks table along with the path to the original drawing. To edit a normal block, you can just edit the record in the Blocks table. When you edit the contents of an xref database, you also have to save the edits to file and update the xref drawing. The code I gave you only works on xrefs. To edit a block, just add an Else clause to the If statement that checks for IsXref.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes