DWG modification without open

DWG modification without open

grobnik
Collaborator Collaborator
963 Views
7 Replies
Message 1 of 8

DWG modification without open

grobnik
Collaborator
Collaborator

Hi to everybody,

I have to modify a small part of each dwg inside a set of 200 DWG, see example "Sheet 100/XX" with "Sheet 100/200". Dwg have been imported from DGN so are not pure autocad and of course a question confirmation of opening will be required before opening. Here the first question: how to trap the confirmation open request dialog box by VBA ? short way could be sendkeys function simulating "enter" as confirmation, but if there will be a better way by VBA could be useful.

The second question is how to modify dwg without open it for editing ? I know that there is a way to have objects inside having access to drawing database and not directly to entity modification, but I'm not so expert with VBA.

Just for start I created a code, of course it's working but require a lot of time into operations... open ->confirmation -> search object and modify it ->save and close, repeat the same operation of 200 files...

Somebody could help me to find a short way ?

Sub MyMacro()
Dim NameOfFile As String
Dim MyPath As String
MyPath = "C:\Users\Utente\Downloads\DWG"
Open MyPath & "\" & "ListDwg.txt" For Input As 1
Do While Not EOF(1)
    Input #1, NameOfFile
    ThisDrawing.Application.Documents.Open MyPath & "\" & NameOfFile
    For Each Object In ThisDrawing.ModelSpace
        If TypeOf Object Is AcadText Or AcadMText Then
            If Right(Object.TextString, 3) = "/XX" Then
               MyString = "/200"
               MyString1 = Left(Object.TextString, Len(Object.TextString) - 3)
               Object.TextString = MyString1 & MyString
            End If
        End If
    Next
    ThisDrawing.Application.ZoomExtents
    ThisDrawing.Save
    ThisDrawing.Close
Loop
Close #1
End Sub

 

0 Likes
Accepted solutions (1)
964 Views
7 Replies
Replies (7)
Message 2 of 8

norman.yuan
Mentor
Mentor
Accepted solution

I have not tried with DWG files that were converted from DGN files, but I think if you use ObjectDBX to open the drawing file in memory and update data/entities in the AxDbDocument, it is very likely you can avoid the said prompt/confirmation message pop up. Also, the batching process speed would be a lot faster.

 

If you have not used ObjectDBX, search this forum/the Internet for "ObjectDBX" and/or "AxDbDocument".

 

 

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 8

grobnik
Collaborator
Collaborator

Hi @norman.yuan 

Thank you for your support, I'll search info on that.

Concerning the DGN, I guess that whenever you import the DGN inside new drawing, enities are the same as Autocad. DGN is MICROSTATION.

I'll keep you informed.

0 Likes
Message 4 of 8

Ed__Jobe
Mentor
Mentor

Hi @grobnik  If you're new to ObjectDBX, the thing to keep in mind is, although you have to reference a separate library, the object model is the same as what you already know in VBA. The only difference is that you work with the database in memory only. There is no Editor, so you can't do things that involve visual things, like create a selectionset or zoom or run SendCommand, as there is no command line to interpret it. But you can iterate paper space and model space and modify entities.

 

 

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

Message 5 of 8

Ed__Jobe
Mentor
Mentor

@grobnik One more thing. To iterate over system files use the VBScript FileSystemObject for working with folders and files. I also have a class that implements Windows system file dialogs for selecting files. I'll find that for you later if you are interested.

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 6 of 8

grobnik
Collaborator
Collaborator

Hi @Ed__Jobe thank you, I'm interested.... "I'll find that for you later if you are interested".

I'm interested too a sample VBA code to have access to ObjectDBX and AxDbDocument if you for sure could have a sample.

Thank you 

Regards

0 Likes
Message 7 of 8

Ed__Jobe
Mentor
Mentor

Hi @grobnik  See this thread I just created for working with files. This thread has a code sample for creating an ObjectDbx file object.

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

Message 8 of 8

grobnik
Collaborator
Collaborator

@norman.yuan @Ed__Jobe 

Thank you for your support I revised my code using AxDbDocument functionality here below the code

Sub CalFunction()
MyPath = "PATH"
Open MyPath & "list.txt" For Input As #1
Do While Not (EOF(1))
    Line Input #1, DwgName
    Call ListAttributes(MyPath & DwgName)
Loop
Close #1
End Sub

Public Sub ListAttributes(DwgName As String)
Dim DbxDoc As New AxDbDocument
DbxDoc.Open DwgName
Dim Entity As AcadEntity
For Each Entity In DbxDoc.ModelSpace
If TypeOf Entity Is AcadText Or TypeOf Entity Is AcadMText Then
    If Right(Entity.TextString, 4) = "/199" Then
        Set objTextEntity = Entity
        Debug.Print Entity.TextString
        Part1 = Left(objTextEntity.TextString, Len(objTextEntity.TextString) - 4)
        Part2 = "/200"
        objTextEntity.TextString = Part1 & Part2
        objTextEntity.Update
        Debug.Print objTextEntity.TextString
    End If
End If
Next
DbxDoc.SaveAs (DwgName)
End Sub

it's working fine, I found a similar code on web for blocks managing and modified little bit.

Thank you 

0 Likes