AutoCAD 2009 - Ensemble d'objets

akram85ing Messages postés 9 Date d'inscription samedi 21 mars 2009 Statut Membre Dernière intervention 29 mai 2009 - 22 mars 2009 à 12:22
pile_poil Messages postés 682 Date d'inscription vendredi 6 avril 2007 Statut Membre Dernière intervention 4 août 2012 - 22 mars 2009 à 17:03
bonjour,
Il s'agit d'un dessin sur AutoCAD 2009 qui contient un ensembles des entités qui forment des contours (un contour : un ensemble des entités qui forment une ''forme'' fermée) .

Aidez moi pour elaborer un code en VBA qui me permet de renvoyer les coordonnées de tous les points dans des tableaux, chaque tableau contient les points d'un contour .
Dans le cas où l'entité n'est pas un ligne on renvoi un nombre quelconque de points  qui appartiennent  à cette  entité.
merci d'avance.

4 réponses

cs_Jack Messages postés 14006 Date d'inscription samedi 29 décembre 2001 Statut Modérateur Dernière intervention 28 août 2015 79
22 mars 2009 à 15:46
Salut
J'ai modifié le nom de ta question qui n'apporte rien au thème de celle-ci : "Aideeeeeeeeeeeeez moi"
Ce forum n'est là que pour aider, alors ce cri n'apporte rien d'autre que de l'énervement.

Je n'y connais rien en Autocad, mais ce genre d'applicatif basé sur du VBA utilise souvent les mêmes structures :
En supposant que monObjet représente ton ensemble d'entités, essaye ça ou du moins, regarde dans l'aide d'Autocadsi tu retrouve quelque chose de ressemblant :

   Dim oEntité As Object
   On Error Resume Next
   For Each oEntité In monObjet
      Debug.Print "Nom", oEntité.Name
      If Err.Number <> 0 Then Debug.Print "Name :: "
      Debug.Print "Gauche", oEntité.Left
      If Err.Number <> 0 Then Debug.Print "Left :: "
      Debug.Print "Droite", oEntité.Right
      If Err.Number <> 0 Then Debug.Print "Right :: "
      Debug.Print "Haut", oEntité.Top
      If Err.Number <> 0 Then Debug.Print "Top :: "
      Debug.Print "Bas", oEntité.Bottom
      If Err.Number <> 0 Then Debug.Print "Bottom :: "
   Next

Vala
Jack, MVP VB
NB : Je ne répondrai pas aux messages privés

<hr />Le savoir est la seule matière qui s'accroit quand on la partage (Socrate)
0
pile_poil Messages postés 682 Date d'inscription vendredi 6 avril 2007 Statut Membre Dernière intervention 4 août 2012 6
22 mars 2009 à 16:22
Jack dans autocad c'est un petit peu plus compliqué 
en effet pour commencer AutoCAd est un logiciel de dessin vectoriel en 3D donc chaque point est identifié par un variant contenant trois valeurs: les position en X, Y et Z (abscisse, ordonnée, profondeur)
pour un simple ligne il y a donc deux fois ce variant pour chacune des extrémités
pour une polyligne il y a autant de variants +1 que de segments
pour un bloc il n'y a qu'un seul variant qui est le point d'insertion de ce bloc dans le dessin
etc ....
ton principe reste toutefois bon mais akram85ing va devoir insérer autant de test qu'il y a d'objets possibles
(une petite trentaine ) ce qui n'a rien d'impossible mais qui reste très lourd à écrire et qui nécessite une excellente connaissance d'AutoCAD et de son VBA

de plus akram85ing les termes de contour, forme fermée, ensemble, ne sont pas des termes AutoCAD ce qui ne facilite pas une éventuelle aide

[reglement.aspx ]si c'est la solution, penser : REPONSE ACCEPTEE
0
pile_poil Messages postés 682 Date d'inscription vendredi 6 avril 2007 Statut Membre Dernière intervention 4 août 2012 6
22 mars 2009 à 16:53
<title>GetWidth Example [ActiveX and VBA Reference: AAR]</title>
<link href="activex.css" rel="Stylesheet" />
<link href="ac.acad_ak.css" type="text/css" rel="StyleSheet" />
extrait de l'aide en ligne du VBA d'AutoCAD pour récupérer les coordonnées des divers point d'une polyligne fermée ou pas
pour l'essayer il suffit de dessiner un rectangle
puis après avoir lancé la macro sélectionner le rectangle en cliquant dessus

Sub Example_GetWidth()
' The following code prompts you to select a lightweight
' polyline, then displays the width of each segment of the
' selected polyline.

Dim returnObj As AcadObject
Dim basePnt As Variant
Dim retCoord As Variant
Dim StartWidth As Double
Dim EndWidth As Double
Dim i, j As Long
Dim nbr_of_segments As Long
Dim nbr_of_vertices As Long
Dim segment As Long
Dim message_string

On Error Resume Next

ThisDrawing.Utility.GetEntity returnObj, basePnt, "Select a polyline"

' Make sure the user selected a polyline.
If Err <> 0 Then
If returnObj.EntityName <> "AcDbPolyline" Then
MsgBox "You did not select a polyline"
End If
Exit Sub
End If

' Obtain the coordinates of each vertex of the selected polyline.
' The coordinates are returned in an array of points.
retCoord = returnObj.Coordinates

segment = 0
i = LBound(retCoord) ' Start index of coordinates array
j = UBound(retCoord) ' End index of coordinates array
nbr_of_vertices = ((j - i) \ 2) + 1 ' Number of vertices in the polyline

' Determine the number of segments in the polyline.
' A closed polyline has as many segments as it has vertices.
' An open polyline has one fewer segment than it has vertices.
' Check the Closed property to determine if the polyline is closed.

If returnObj.Closed Then
nbr_of_segments = nbr_of_vertices
Else
nbr_of_segments = nbr_of_vertices - 1
End If

' Get the width of each segment of the polyline
Do While nbr_of_segments > 0

' Get the width of the current segment
returnObj.GetWidth segment, StartWidth, EndWidth

message_string = "The segment that begins at " & retCoord(i) & "," & retCoord(i + 1) _
& " has a start width of " & StartWidth & " and an end width of " & EndWidth
MsgBox message_string, , "GetWidth Example"

' Prepare to obtain width of next segment, if any
i = i + 2
segment = segment + 1
nbr_of_segments = nbr_of_segments - 1
Loop

End Sub




[reglement.aspx
]




si c'est la solution,
penser : REPONSE ACCEPTEE
0
pile_poil Messages postés 682 Date d'inscription vendredi 6 avril 2007 Statut Membre Dernière intervention 4 août 2012 6
22 mars 2009 à 17:03
oups ! petit probleme de mise en page!

Sub Example_GetWidth()
    ' The following code prompts you to select a lightweight
    ' polyline, then displays the width of each segment of the
    ' selected polyline.
  
    Dim returnObj As AcadObject
    Dim basePnt As Variant
    Dim retCoord As Variant
    Dim StartWidth As Double
    Dim EndWidth As Double
    Dim i, j As Long
    Dim nbr_of_segments As Long
    Dim nbr_of_vertices As Long
    Dim segment As Long
    Dim message_string
             
    On Error Resume Next
  
    ThisDrawing.Utility.GetEntity returnObj, basePnt, "Select a polyline"
      
    ' Make sure the user selected a polyline.
    If Err <> 0 Then
        If returnObj.EntityName <> "AcDbPolyline" Then
            MsgBox "You did not select a polyline"
        End If
        Exit Sub
    End If
   
    ' Obtain the coordinates of each vertex of the selected polyline.
    ' The coordinates are returned in an array of points.
    retCoord = returnObj.Coordinates
   
    segment = 0
    i = LBound(retCoord)                 ' Start index of coordinates array
    j = UBound(retCoord)                 ' End index of coordinates array
    nbr_of_vertices = ((j - i) \ 2) + 1  ' Number of vertices in the polyline
   
    ' Determine the number of segments in the polyline.
    ' A closed polyline has as many segments as it has vertices.
    ' An open polyline has one fewer segment than it has vertices.
    ' Check the Closed property to determine if the polyline is closed.
   
    If returnObj.Closed Then
        nbr_of_segments = nbr_of_vertices
    Else
        nbr_of_segments = nbr_of_vertices - 1
    End If
   
    ' Get the width of each segment of the polyline
    Do While nbr_of_segments > 0
         
        ' Get the width of the current segment
        returnObj.GetWidth segment, StartWidth, EndWidth
       
        message_string = "The segment that begins at " & retCoord(i) & "," & retCoord(i + 1) _
            & " has a start width of " & StartWidth & " and an end width of " & EndWidth
        MsgBox message_string, , "GetWidth Example"
    
        ' Prepare to obtain width of next segment, if any
        i = i + 2
        segment = segment + 1
        nbr_of_segments = nbr_of_segments - 1
    Loop
     
End Sub

[reglement.aspx ]si c'est la solution, penser : REPONSE ACCEPTEE
0
Rejoignez-nous