MicroStation V8: Placer une cellule avec origine, échelle et rotation par 2 points

Comment insérer une cellule dans MicroStation V8 en définissant son point d’origine avec un premier clic, puis son orientation et son échelle de manière dynamique (variable) avec un second clic, sans passer par une troisième saisie ?

La fonctionnalité standard de placement de cellule interactive dans MicroStation V8 permet de définir l’origine et l’orientation, mais la gestion de l’échelle est souvent séparée ou moins intuitive pour une définition par deux points dynamiques. Pour obtenir un placement de cellule où le second point définit à la fois l’orientation et l’échelle de manière proportionnelle, une macro VBA personnalisée est la solution la plus efficace.

Voici la procédure détaillée pour implémenter et utiliser cette solution :

  1. PRÉPARATION DE LA MACRO VBA

    • Ouvrez l’éditeur VBA de MicroStation (Utilitaires > Macros > Gestionnaire de projets VBA ou touche Alt+F11).

    • Dans l’explorateur de projets (fenêtre de gauche), cliquez droit sur votre projet VBA (par défaut untitled.mvba ou créez-en un nouveau) et choisissez Insérer > Module.

    • Renommez ce module (par exemple, ModulePrincipal). Copiez-y le code suivant :

      Sub Placecell0()
      
      If ActiveSettings.CellName = "" Then
      
      MsgBox "Aucune cellule active sélectionnée."
      
      Exit Sub
      
      End If
      
      Dim oCel As CellElement
      
      Set oCel = CreateCellElement2(ActiveSettings.CellName, Point3dZero, Point3dFromXY(1, 1), True, Matrix3dIdentity)
      
      If oCel.Range.Low.X - oCel.Range.High.X = 0 Then
      
      MsgBox "Cellule invalide ou de taille nulle."
      
      Exit Sub
      
      End If
      
      CommandState.StartPrimitive New p_cell_anG_Sca
      
      End Sub
      
    • Cliquez droit à nouveau sur votre projet VBA et choisissez Insérer > Module de classe.

    • Renommez ce module de classe (par exemple, p_cell_anG_Sca). Copiez-y le code suivant :

      Implements IPrimitiveCommandEvents
      
      Private m_atPoints(0 To 1) As Point3d
      
      Private m_nPoints As Integer
      
      Dim Lg2 As Double
      
      Dim LgPt As Double
      
      Dim Algpt As Double
      
      Dim Propp As Double
      
      Private Sub IPrimitiveCommandEvents_Cleanup()
      
      End Sub
      
      Private Sub IPrimitiveCommandEvents_DataPoint(Point As Point3d, ByVal View As View)
      
      If m_nPoints = 0 Then
      
      CommandState.StartDynamics
      
      m_atPoints(0) = Point
      
      m_nPoints = 1
      
      ShowPrompt "Placez le point final (orientation et échelle)"
      
      Dim cel1 As CellElement
      
      Set cel1 = CreateCellElement2(ActiveSettings.CellName, m_atPoints(0), Point3dFromXY(1, 1), True, Matrix3dIdentity)
      
      LgPt = Abs(Point3dDistance(cel1.Range.Low, cel1.Origin))
      
      Algpt = Atn2(cel1.Origin.Y - cel1.Range.Low.Y, cel1.Origin.X - cel1.Range.Low.X)
      
      Propp = Abs(cel1.Range.Low.X - cel1.Range.High.X)
      
      ElseIf m_nPoints = 1 Then
      
      m_atPoints(1) = Point
      
      Dim oCel As CellElement
      
      Set oCel = CreateCellElement2(ActiveSettings.CellName, Point3dAddAngleDistance(m_atPoints(0), Algpt + Atn2(m_atPoints(1).Y - m_atPoints(0).Y, m_atPoints(1).X - m_atPoints(0).X), LgPt * Lg2 / Propp, 1), Point3dFromXY(Lg2 / Propp, Lg2 / Propp), True, Matrix3dFromAxisAndRotationAngle(2, Atn2(m_atPoints(1).Y - m_atPoints(0).Y, m_atPoints(1).X - m_atPoints(0).X)))
      
      ActiveModelReference.AddElement oCel
      
      oCel.Redraw
      
      m_atPoints(0) = m_atPoints(1)
      
      End If
      
      End Sub
      
      Private Sub IPrimitiveCommandEvents_Dynamics(Point As Point3d, ByVal View As View, ByVal DrawMode As MsdDrawingMode)
      
      CommandState.ParseAll = False
      
      If m_nPoints = 1 Then
      
      m_atPoints(1) = Point
      
      Dim oCel As CellElement
      
      Lg2 = Abs(Point3dDistance(m_atPoints(0), Point))
      
      Set oCel = CreateCellElement2(ActiveSettings.CellName, Point3dAddAngleDistance(m_atPoints(0), Algpt + Atn2(m_atPoints(1).Y - m_atPoints(0).Y, m_atPoints(1).X - m_atPoints(0).X), LgPt * Lg2 / Propp, 1), Point3dFromXY(Lg2 / Propp, Lg2 / Propp), True, Matrix3dFromAxisAndRotationAngle(2, Atn2(m_atPoints(1).Y - m_atPoints(0).Y, m_atPoints(1).X - m_atPoints(0).X)))
      
      oCel.Redraw DrawMode
      
      Dim oEl As LineElement
      
      Set oEl = CreateLineElement1(Nothing, m_atPoints)
      
      oEl.Redraw DrawMode
      
      End If
      
      End Sub
      
      Private Sub IPrimitiveCommandEvents_Keyin(ByVal Keyin As String)
      
      End Sub
      
      Private Sub IPrimitiveCommandEvents_Reset()
      
      CommandState.StartPrimitive Me
      
      m_nPoints = 0
      
      End Sub
      
      Private Sub IPrimitiveCommandEvents_Start()
      
      ShowPrompt "Point d'insertion de la cellule"
      
      End Sub
      
    • Enregistrez votre projet VBA (par exemple, MonProjetCellule.mvba).

  2. UTILISATION DE LA MACRO

    • Définir la cellule active : Avant de lancer la macro, assurez-vous qu’une cellule est bien définie comme « active » dans MicroStation (Outils > Cellules > Définir cellule active).
    • Lancer la macro : Dans la ligne de commande de MicroStation, utilisez la commande vba run [NomProjetVBA].ModulePrincipal.Placecell0 (ex: vba run MonProjetCellule.ModulePrincipal.Placecell0).
    • Interaction :
      • Le premier clic définira le point d’insertion (origine) de la cellule.
      • Le second clic définira l’orientation de la cellule et son échelle. L’échelle sera proportionnelle à la distance entre le premier et le second point, par rapport à la taille originale de la cellule.
  3. FONCTIONNEMENT DE LA MACRO
    Cette macro VBA intercepte les clics de l’utilisateur pour :

    • Premier point : Capture le point d’insertion de la cellule.
    • Dynamique (mouvement de la souris) : Calcule en temps réel la distance et l’angle entre le premier point et la position actuelle du curseur. Elle utilise ces valeurs pour redimensionner et faire pivoter la cellule active, offrant un aperçu dynamique.
    • Deuxième point : Valide la position finale, l’orientation et l’échelle de la cellule en fonction du second point cliqué.

Note sur les alternatives :

  • La commande native place cell interactive;%d;1;1 permet l’orientation par le second point mais fixe l’échelle à 1:1. Elle ne répond pas au besoin d’une échelle variable.
  • Des applications MDL (MicroStation Development Language) ou d’autres macros Basic peuvent exister, mais la solution VBA ci-dessus est directement applicable et personnalisable pour ce besoin spécifique de placement dynamique par deux points.