Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - dockee

Pages: [1]
1
Dimensions / Re: Some basic dimensions function
« on: May 13, 2013, 05:17:16 PM »
This is the solution to put an isométric dim as this picture.




Code: [Select]
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common


Public Class Main

' Programme de cotation isomètrique
' mai 2013 REV 1.0
' Auteur : F. LEGAY


#Region "programme principal"

<CommandMethod("COTISO")> _
Sub Main()

' Déclaration des variables
Dim OldLayer = Application.GetSystemVariable("clayer")
Dim OldOrtho = Application.GetSystemVariable("orthomode")
Dim OldSnap = Application.GetSystemVariable("snapmode")
Dim CotAng As Double
Dim plan As Integer = Application.GetSystemVariable("snapisopair")
Dim dimStyleName As String = "iso8-30"
Dim Doc As Document = Application.DocumentManager.MdiActiveDocument
Dim Db As Database = HostApplicationServices.WorkingDatabase
Dim Ed As Editor = Doc.Editor

' Activation de la couche pour dessinner les cotations
Application.SetSystemVariable("clayer", "10 - COTATION")

' Demande le premier point
Dim Pt1 As New Point3d
Dim Opt1 As New PromptPointOptions(vbLf & "Entrer le premier point")
Dim Res1 As PromptPointResult = Ed.GetPoint(Opt1)

If Res1.Status = PromptStatus.OK Then
Pt1 = Res1.Value
End If

' Demande le deuxième point
Dim Pt2 As New Point3d
Dim Opt2 As New PromptPointOptions(vbLf & "Entrer le deuxième point")
Dim Res2 As PromptPointResult = Ed.GetPoint(Opt2)

If Res2.Status = PromptStatus.OK Then
Pt2 = Res2.Value
End If

Dim ang As Double = AngleFromXAxis(Pt1, Pt2)
Dim angdeg As String = CType((180 * ang / Math.PI), String)

' Demande la position de la ligne de cote
Dim Pt3 As New Point3d
Dim Opt3 As New PromptPointOptions(vbLf & "Entrer la position de la ligne de cote")
Dim Res3 As PromptPointResult = Ed.GetPoint(Opt3)

If Res3.Status = PromptStatus.OK Then
Pt3 = Res3.Value
End If

' Demande la position de la ligne de cote
Dim DimStr As String = ""
Dim StrOpt As New PromptStringOptions(vbLf & "Entrer la valeur de la cotation")
Dim ResStr As PromptResult = Ed.GetString(StrOpt)

If ResStr.Status = PromptStatus.OK Then
DimStr = ResStr.StringResult
End If

'Détermine le style de cotation en cours
Using Tr As Transaction = Db.TransactionManager.StartTransaction

Dim DimTbl As DimStyleTable = CType(Tr.GetObject(Db.DimStyleTableId, OpenMode.ForRead), DimStyleTable)
If DimTbl.Has(dimStyleName) Then
Dim DimRecord As DimStyleTableRecord = CType(Tr.GetObject(DimTbl(dimStyleName), OpenMode.ForRead), DimStyleTableRecord)
If DimRecord.ObjectId <> Db.Dimstyle Then
Db.Dimstyle = DimRecord.ObjectId
Db.SetDimstyleData(DimRecord)
End If
End If
Tr.Commit()

End Using

' Définit l'angle et de style de cotation a utiliser
Select Case angdeg
Case "90"
Select Case plan
Case 0
dimStyleName = "iso830"
CotAng = CType((Math.PI * 240 / 180.0), Double)
Case 2
dimStyleName = "iso8-30"
CotAng = CType((Math.PI * 120 / 180.0), Double)
End Select
Case "270"
Select Case plan
Case 0
dimStyleName = "iso830"
CotAng = CType((Math.PI * 240 / 180.0), Double)
Case 2
dimStyleName = "iso8-30"
CotAng = CType((Math.PI * 120 / 180.0), Double)
End Select
Case "330"
Select Case plan
Case 0
dimStyleName = "iso8-30"
CotAng = CType((Math.PI * 120 / 180.0), Double)
Case 1
dimStyleName = "iso830"
CotAng = CType((Math.PI * 240 / 180.0), Double)
End Select
Case "150"
Select Case plan
Case 0
dimStyleName = "iso8-30"
CotAng = CType((Math.PI * 120 / 180.0), Double)
Case 1
dimStyleName = "iso830"
CotAng = CType((Math.PI * 240 / 180.0), Double)
End Select
Case "30"
Select Case plan
Case 1
dimStyleName = "iso8-30"
CotAng = CType((Math.PI * 120 / 180.0), Double)
Case 2
dimStyleName = "iso830"
CotAng = CType((Math.PI * 240 / 180.0), Double)
End Select
Case "210"
Select Case plan
Case 1
dimStyleName = "iso8-30"
CotAng = CType((Math.PI * 120 / 180.0), Double)
Case 2
dimStyleName = "iso830"
CotAng = CType((Math.PI * 240 / 180.0), Double)
End Select
End Select


' Création de la cotation
Using Tr As Transaction = Db.TransactionManager.StartTransaction

Dim btr As BlockTableRecord = CType(Tr.GetObject(Db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
Dim dtb As DimStyleTable = CType(Tr.GetObject(Db.DimStyleTableId, OpenMode.ForRead), DimStyleTable)
If Not dtb.Has(dimStyleName) Then Return
Dim dtr As DimStyleTableRecord = CType(Tr.GetObject(dtb(dimStyleName), OpenMode.ForRead), DimStyleTableRecord)

Dim odim As AlignedDimension = New AlignedDimension(Pt1, Pt2, Pt3, DimStr, dtr.ObjectId)
odim.SetDatabaseDefaults()
odim.Oblique = CotAng
btr.AppendEntity(odim)
Tr.AddNewlyCreatedDBObject(odim, True)

Tr.Commit()

End Using

'Application.SetSystemVariable("snapstyl", 1)
Application.SetSystemVariable("clayer", OldLayer)



  End Sub


  Public Function AngleFromXAxis(ByVal p1 As Point3d, ByVal p2 As Point3d) As Double

    Return New Vector2d(p2.X - p1.X, p2.Y - p1.Y).Angle

  End Function


#End Region


End Class

Sorry if it too long that put my code.

2
3D entities / Re: AutoCAD 2011 & VB.net Express 2008
« on: April 03, 2013, 07:40:12 PM »
I think the problem come from security framework.

See capsol command to make authorization on worker pc.


3
Dimensions / Re: Some basic dimensions function
« on: March 15, 2013, 09:54:33 PM »
It's not necessary. I find solution. My calculaltion on angle is not right.

When i finalize my project, i Put a picture with the part of code.

Thanks.


4
Dimensions / Re: Some basic dimensions function
« on: March 13, 2013, 10:33:40 PM »
hi,

I manage to create an aligneddim but I have one parameter to put this last in a grid iso autocad.

Can you help me.

Thanks.

5
This site / Re: Welcome on the AutoCAD .NET developpers forums
« on: March 11, 2013, 07:56:04 PM »
Hi my name is fabrice.

Thank  for this site.


Pages: [1]