tyrese69_ Posté(e) le 22 février 2007 Posté(e) le 22 février 2007 Bonsoir,Aprés avoir lu le sujet sur les objets DBX du forum vlisp,j'ai cherché sur le net ce qui existe en VBA. Un peut en vrac le résultat ! Juste un petit point par rapport Vlisp, par le VBA l'accès aux possibiltés de ces fonctions estbeaucoup plus aisé. Mais le but de toute chose varie selon chacun ! Daniel OLIVESLyon - FRANCE Option Explicit ' ModuleType MessPunkt Rechtswert As Double Hochwert As Double Höhe As Double PNR As StringEnd Type Public Punkte() As MessPunkt' ' Opening a drawing with ObjectDBX'Function dbxOpen(fn As String) As AXDB16Lib.AxDbDocument' If Dir(fn) <> "" Then' Dim dwgX As New AXDB16Lib.AxDbDocument' dwgX.Open (fn)'' If Err.Number <> 0 Then' If Err.Number <> -2147467259 Then 'Invalid filename' regObjectDBX' dwgX.Open (fn)' End If' End If' Set dbxOpen = dwgX' End If'End Function' Sub ImportLayout(ByVal lyName As String, ByVal fileName As String) Dim cmdName As String cmdName = Join(Split(fileName, "\", , 1), "/") cmdName = "(command ""._Layout"" ""_T"" """ & cmdName & """ """ & lyName & """) " ThisDrawing.SendCommand cmdNameEnd Sub' ' Add reference to AutoCAD/ObjectDBX Common 16.0 Type Library (axdb16enu.dll)' This samples copies all dimstyles from specified drawing to the current drawing' Existing dimstyles are not affectedPublic Sub ImportDimstyles() Dim oAxDbDoc As New AxDbDocument oAxDbDoc.Open "c:\DimStyles.dwg" Dim oObj() As Object Dim oDs As AcadDimStyle Dim i As Integer For i = 0 To oAxDbDoc.DimStyles.Count - 1 ReDim Preserve oObj(i) Set oObj(i) = oAxDbDoc.DimStyles(i) Next oAxDbDoc.CopyObjects oObj, ThisDrawing.Database.DimStylesEnd Sub' ' 2000-03-08' By Jimmy Bergmark' Copyright © 1997-2003 JTB World, All Rights Reserved ' Website: www.jtbworld.com' E-mail: info@jtbworld.com' Runs in All AutoCAD version if axdb1'x'.dll (must be referenced)' Example of batch for listing all layers on all drawings in a directory.'' http://www.jtbworld.com/VBA/listlayer.htm'' Corrected by d.OLIVES - for All version and test vbReadOnly' 2007-02-02 Private Sub ListLayers() Dim indir As StringDim elem As ObjectDim filenom As StringDim WholeFile As StringDim newHeight As DoubleDim objDbx As AxDbDocumentDim MyAttr As IntegerDim acadTyp As String acadTyp = Left$(ThisDrawing.Application.Version, 2) Set objDbx = ThisDrawing.Application.GetInterfaceObject("ObjectDBX.AxDbDocument." & acadTyp) indir = "C:\Program Files\Egid\Cache"filenom = Dir$(indir & "\*.dwg")MyAttr = GetAttr(indir & "\" & filenom)Do While filenom <> "" ThisDrawing.Utility.Prompt vbCrLf & "File: " & filenom ThisDrawing.Utility.Prompt vbCrLf & "-----------------" WholeFile = indir & "\" & filenom objDbx.Open WholeFile For Each elem In objDbx.Layers ThisDrawing.Utility.Prompt vbCrLf & elem.name Next Set elem = Nothing If (MyAttr And vbReadOnly) <> vbReadOnly Then objDbx.SaveAs WholeFile End If filenom = Dir$ ThisDrawing.Utility.Prompt vbCrLfLoopEnd Sub' '' 2000-03-08' By Jimmy Bergmark' Copyright © 1997-2003 JTB World, All Rights Reserved' Website: www.jtbworld.com' E-mail: info@jtbworld.com' Runs in All AutoCAD version if axdb1'x'.dll (must be referenced)' Example of batch for listing all xrefs on all drawings in a directory.'' http://www.jtbworld.com/VBA/listxref.htm'' Corrected by d.OLIVES - for All version and test vbReadOnly' 2007-02-02 Private Sub ListXREF() Dim indir As StringDim elem As ObjectDim filenom As StringDim WholeFile As StringDim newHeight As DoubleDim objDbx As AxDbDocumentDim MyAttr As IntegerDim acadTyp As String acadTyp = Left$(ThisDrawing.Application.Version, 2) Set objDbx = ThisDrawing.Application.GetInterfaceObject("ObjectDBX.AxDbDocument." & acadTyp)indir = "C:\Program Files\Egid\Cache"filenom = Dir$(indir & "\*.dwg")MyAttr = GetAttr(indir & "\" & filenom)Do While filenom <> "" ThisDrawing.Utility.Prompt vbCrLf & "File: " & filenom ThisDrawing.Utility.Prompt vbCrLf & "-----------------" WholeFile = indir & "\" & filenom objDbx.Open WholeFile For Each elem In objDbx.Blocks If elem.IsXRef = True Then ThisDrawing.Utility.Prompt vbCrLf & elem.name End If Next Set elem = Nothing If (MyAttr And vbReadOnly) <> vbReadOnly Then objDbx.SaveAs WholeFile End If filenom = Dir$ ThisDrawing.Utility.Prompt vbCrLfLoopEnd Sub' ' Runs in All AutoCAD version if axdb1'x'.dll (must be referenced)' Example of batch for listing all SummaryInfo = DWG Properties in a directory.' by d.OLIVES - for All version and test vbReadOnly' 2007-02-02 Private Sub ListPROPS() Dim indir As StringDim elem As ObjectDim filenom As StringDim WholeFile As StringDim newHeight As DoubleDim objDbx As AxDbDocumentDim MyAttr As IntegerDim acadTyp As String Dim myProps As AcadSummaryInfoSet myProps = ThisDrawing.SummaryInfomyProps.RevisionNumber = 1Set myProps = Nothing acadTyp = Left$(ThisDrawing.Application.Version, 2) Set objDbx = ThisDrawing.Application.GetInterfaceObject("ObjectDBX.AxDbDocument." & acadTyp)indir = "C:\Program Files\Egid\Cache"filenom = Dir$(indir & "\*.dwg")MyAttr = GetAttr(indir & "\" & filenom)Do While filenom <> "" ThisDrawing.Utility.Prompt vbCrLf & "File: " & filenom ThisDrawing.Utility.Prompt vbCrLf & "-----------------" WholeFile = indir & "\" & filenom objDbx.Open WholeFile ThisDrawing.Utility.Prompt vbCrLf & "Auteur : " & objDbx.SummaryInfo.Author Set elem = Nothing If (MyAttr And vbReadOnly) <> vbReadOnly Then objDbx.SaveAs WholeFile End If filenom = Dir$ ThisDrawing.Utility.Prompt vbCrLfLoopEnd Sub' ' Pour VB'http://discussion.autodesk.com/thread.jspa?messageID=5167190Public Sub DbxRefTest()' To test, set references to:'Microsoft Visual Basic for Applications Extensibility 5.3'C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB'AutoCAD/ObjectDBX Common 16.0 Type Library'C:\Program Files\Common Files\Autodesk Shared\axdb16enu.tlb'Run in: AutoCAD 2007 Dim Dbx As AxDbDocumentDim i As IntegerDim oVBE As VBE Dim oVBP As VBProject Dim Version As String Version = Mid(ThisDrawing.GetVariable("acadver"), 1, 2) 'Fix ReferenceSet oVBE = Application.VBESet oVBP = oVBE.ActiveVBProject With oVBP.References For i = 1 To .Count If .Item(i).name Like "AXDBLib" Then If Not .Item(i).Description Like _ "AutoCAD/ObjectDBX Common " & _ Version & ".0 Type Library" Then .Remove .Item(i) .AddFromFile _ "C:\Program Files\Common Files" & _ "\Autodesk Shared\axdb" & _ Version & "enu.tlb" End If GoTo FixRefDone End If NextEnd WithFixRefDone:Set oVBP = NothingSet oVBE = Nothing 'Get Template DbxIf CInt(Version) < 16 Then Set Dbx = AcadApplication.GetInterfaceObject("ObjectDBX.AxDbDocument")Else Set Dbx = AcadApplication.GetInterfaceObject("ObjectDBX.AxDbDocument." & Version) 'End IfDbx.Open ThisDrawing.Application.Preferences.Files.QNewTemplateFile 'Clear DbxSet Dbx = Nothing End Sub' Sub TestATTRIBUTS() Dim objDbx As Object'Dim arx As AxDbDocumentDim col(0) As ObjectDim blockdef As AcadBlockDim acadTyp As String Dim indir As StringDim elem As ObjectDim filenom As StringDim WholeFile As StringDim newHeight As Double'Dim objDbx As AxDbDocumentDim MyAttr As Integer Dim Anzahl As LongDim Entity As AcadEntityDim BlockRef As AcadBlockReferenceDim InsPkt As VariantDim PNR As StringDim Attr As AcadAttributeReferenceReDim Punkte(0 To 0)acadTyp = Left$(ThisDrawing.Application.Version, 2) ' For Each blockdef In objDbx.Blocks' If blockdef.IsLayout = False Then' Set col(0) = blockdef' Call objDbx.CopyObjects(col, ThisDrawing.Blocks)' End If' Next blockdef Set objDbx = ThisDrawing.Application.GetInterfaceObject("ObjectDBX.AxDbDocument." & acadTyp)indir = "C:\TEMP\T_Essai"filenom = Dir$(indir & "\*.dwg")MyAttr = GetAttr(indir & "\" & filenom) Do While filenom <> "" WholeFile = indir & "\" & filenomOn Error GoTo Err_TrapobjDbx.Open WholeFile For Each Entity In objDbx.PaperSpace If Entity.EntityType = acBlockReference Then If Entity.name = "Cartouche" Then Anzahl = Anzahl + 1 Set BlockRef = Entity InsPkt = BlockRef.insertionPoint ReDim Preserve Punkte(0 To UBound(Punkte) + 1) Punkte(UBound(Punkte)).Rechtswert = InsPkt(0) Punkte(UBound(Punkte)).Hochwert = InsPkt(1) Punkte(UBound(Punkte)).Höhe = InsPkt(2) If BlockRef.HasAttributes Then Dim varAttributes As Variant Dim i As Integer Dim strAttributes As String ThisDrawing.Utility.Prompt vbCrLf & "File: " & filenom ThisDrawing.Utility.Prompt vbCrLf & "-----------------" varAttributes = BlockRef.GetAttributes For i = LBound(varAttributes) To UBound(varAttributes) strAttributes = strAttributes & " Tag: " & varAttributes(i).TagString & _ " Value: " & varAttributes(i).textString & " " ThisDrawing.Utility.Prompt vbCrLf & "Auteur : " & strAttributes ThisDrawing.SummaryInfo.Author = varAttributes(i).textString strAttributes = "" Next PNR = 12345678 Punkte(UBound(Punkte)).PNR = PNR If (MyAttr And vbReadOnly) <> vbReadOnly Then objDbx.SaveAs WholeFile End If End If End If End IfNext Entity ' Cas du fichier déjà ouvert passe au fichie suivantsuite:filenom = Dir$ThisDrawing.Utility.Prompt vbCrLfLoopSet objDbx = NothingThisDrawing.Utility.Prompt vbCrLfExit Sub Err_Trap:Select Case Err.Number' Cas du fichier déjà ouvertCase -2147467259 MsgBox "Attention ce fichier est déjà ouvert veuillez d'abord le fermer !", _ vbCritical, "Gestion des cartouches" Err.Clear GoTo suiteCase Else Err.Clear Exit Sub ' Sortie sous-routineEnd Select End Sub' - - - - - - - - - - - - - - - - - - - - - - - - - - Sub TestobjDbx() Dim objDbx As Object'Dim arx As AxDbDocumentDim col(0) As ObjectDim blockdef As AcadBlockDim acadTyp As String acadTyp = Left$(ThisDrawing.Application.Version, 2) Set objDbx = ThisDrawing.Application.GetInterfaceObject("ObjectDBX.AxDbDocument." & acadTyp)objDbx.Open "C:\Program Files\Egid\Modeles\2002\Cartouche.DWG" For Each blockdef In objDbx.Blocks If blockdef.IsLayout = False Then Set col(0) = blockdef Call objDbx.CopyObjects(col, ThisDrawing.Blocks) End If Next blockdef Set objDbx = NothingEnd Sub
Messages recommandés
Créer un compte ou se connecter pour commenter
Vous devez être membre afin de pouvoir déposer un commentaire
Créer un compte
Créez un compte sur notre communauté. C’est facile !
Créer un nouveau compteSe connecter
Vous avez déjà un compte ? Connectez-vous ici.
Connectez-vous maintenant