Linetype question

Linetype question

J-Rocks
Collaborator Collaborator
953 Views
5 Replies
Message 1 of 6

Linetype question

J-Rocks
Collaborator
Collaborator

Hello guys

 

I wonder how to change or set the Line type of line object in my codes below .

 

Dim acLine As Line = New Line(New Point3d(0, 0, 0), New Point3d(12, 3, 0))
                acLine.SetDatabaseDefaults()
                acLine.ColorIndex = 1

 Can someone help me and explain the way to get that working ?

 

Thanks in advance .

 

John

0 Likes
Accepted solutions (1)
954 Views
5 Replies
Replies (5)
Message 2 of 6

_gile
Consultant
Consultant

Hi,

 

Just set the linetype property of the entity:

acLine.Linetype = "HIDDEN";

 but you'd rather check if the line type is loaded before.

LinetypeTable ltt =
    (LinetypeTable)tr.GetObject(db.LinetypeTableId, OpenMode.ForRead);
if (ltt.Has("HIDDEN"))
    acLine.Linetype = "HIDDEN";

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 6

J-Rocks
Collaborator
Collaborator

 

Thank you gile .

 

I am sorry I am a new with VB.net and C# .

 

I added your codes into the program but I failed . Can you please just include your codes in my prorgam ?

 

 

Public Class rocks
        <CommandMethod("AddLine")>
        Public Sub AddLine()
            '' Get the current document and database
            Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
            Dim acCurDb As Database = acDoc.Database
            '' Start a transaction
            Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
                '' Open the Block table for read
                Dim acBlkTbl As BlockTable
                acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)
                '' Open the Block table record Model space for write
                Dim acBlkTblRec As BlockTableRecord
                acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace),
                                                                       OpenMode.ForWrite)
                Dim acLine As Line = New Line(New Point3d(0, 0, 0), New Point3d(12, 3, 0))
                acLine.SetDatabaseDefaults()
                acLine.ColorIndex = 1
                'acLine.Linetype = 
                acLine.LineWeight = LineWeight.LineWeight040
                '' Add the new object to the block table record and the transaction
                acBlkTblRec.AppendEntity(acLine)
                acTrans.AddNewlyCreatedDBObject(acLine, True)
                '' Save the new object to the database
                acTrans.Commit()
            End Using
        End Sub
    End Class

 

thank you very much.

0 Likes
Message 4 of 6

J-Rocks
Collaborator
Collaborator

I think I added your codes correctly but I need to load "HIDDEN" linetype if it is not already loaded , how to do that ?

 

 Dim ltt As LinetypeTable
                ltt = acTrans.GetObject(acCurDb.LinetypeTableId, OpenMode.ForRead)
                If (ltt.Has("HIDDEN")) Then
                    acLine.Linetype = "HIDDEN"
Else ...... End If

 Thank you

0 Likes
Message 5 of 6

_gile
Consultant
Consultant
Accepted solution

You can try (not sure about VB syntax):

 

If Not ltt.Has("HIDDEN") Then
    acCurDb.LoadLineTypeFile("HIDDEN", "acad.lin")
End If
acLine.Linetype = "HIDDEN"

 You may have a look to the docs.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 6 of 6

J-Rocks
Collaborator
Collaborator

@Anonymous_gile wrote:

You can try (not sure about VB syntax):

 

If Not ltt.Has("HIDDEN") Then
    acCurDb.LoadLineTypeFile("HIDDEN", "acad.lin")
End If
acLine.Linetype = "HIDDEN"

 You may have a look to the docs.


That works very well , thank you Gile for your great help .

 

and thanks for the link that helps much to understand the complete process .

0 Likes