Problem with DATATYPE VARIANT in AutoCAD with using VB.NET

Problem with DATATYPE VARIANT in AutoCAD with using VB.NET

Anonymous
Not applicable
1,179 Views
4 Replies
Message 1 of 5

Problem with DATATYPE VARIANT in AutoCAD with using VB.NET

Anonymous
Not applicable

I have to plot the layout using SetLayoutsToPlot Method using VB.NET. But I getting one error with Data Type - VARIANT. I found the help page in acadauto.chm there was this text.

 

object.SetLayoutsToPlot (layoutList) 

Object

Plot
The object or objects this method applies to. 

layoutList

Variant; input-only
An array of layout names representing the layouts to plot. 

Remarks 

This method may become obsolete and may be removed in a future version of AutoCAD. 

If the layoutList parameter is NULL or this method is not called at all, the active layout is sent to the plot. 

After each call to the PlotToFile or PlotToDevice method, the default layout to plot is reset to the active layout. To specify any layout other than the active layout, you must call the SetLayoutsToPlot method before each plot.

The problem is that I'm haven't the Data Type 'Variant' in VB.NET. I have only Data Type 'Object'. And this method is doesn't work! But I need to use that method.

Please, tell me how could I to get solution by this problem.

 

 

 

 

0 Likes
Accepted solutions (1)
1,180 Views
4 Replies
Replies (4)
Message 2 of 5

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

you are correct, datatype "Variant" is only defined within VBA, but not within VB.NET.

So you can use in VB.NET the type "Object" instead.

 

Show us your source code so we see what is not working when you use "Object" instead of "Variant".

 

- alfred -

 

BTW: there is a special forum for AutoCAD and .NET >>>there<<< (if the admin not already moved this thread to that forum 😉 )

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 3 of 5

Anonymous
Not applicable

Thanks for answer Alfred 🙂

 

My code before:

 

    Private Function FORCIBLY_AUTOCAD_TO_PDF_BY_ONE_BY_LAYOUTS()

        ' Принудительно печатаем листы, если пакетная печать не удалась

        Dim acad As Object
        Dim TextLine As String
        Dim LayoutParameters() As String
        ReDim LayoutParameters(1000)
        Dim N As Integer
        Dim LayP As Object
        Dim Need_Path_Name As String
        Dim PDF_File_Name As String

        Dim Layout_Names(0) As String
        Dim LrsToPlot As Object

        N = -1


        FileOpen(1, Me.Plot_File, OpenMode.Input)
        Do While Not EOF(1)
            TextLine = LineInput(1)
            If InStr(TextLine, "ЛИСТ") <> 0 Then
                N = N + 1
                LayoutParameters(N) = TextLine
            End If
        Loop
        FileClose(1)

        ReDim Preserve LayoutParameters(N)


            acad = CreateObject("Autocad.Application")

            Do While acad.Documents.Count > 0
                acad.Documents(0).Close(False)
            Loop

            Need_Path_Name = Me.DWG_Dir & "\" & Me.File_Name_Without_Extension & ".dwg"
            acad.Documents.Open(Need_Path_Name)


            For i = LBound(LayoutParameters) To UBound(LayoutParameters)
                LayP = Split(LayoutParameters(i), " | ")

                PDF_File_Name = Me.PDF_Dir & "\" & LayP(1) & ".pdf"
                acad.ActiveDocument.SendCommand("_filedia" & vbCr & "0" & vbCr)
                acad.ActiveDocument.SendCommand("_cmddia" & vbCr & "0" & vbCr)

                Layout_Names(0) = LayP(1)
                LrsToPlot = Layout_Names
                
                ' This fragment of code doesn't work
                acad.ActiveDocument.Plot.SetLayoutToPlot (LrsToPlot)   ' <---- ERROR, Because it's OBJECT
                acad.Plot.PlotToFile(PDF_File_Name, "DWG_To_PDF_Gallurgy.pc3")
                ' End fragment of code


                    Do While acad.GetAcadState.IsQuiescent = False
                        If acad.GetAcadState.IsQuiescent = True Then
                            Exit Do
                        End If
                    Loop

            Next i

        acad.Visible = False

            Do While acad.Documents.Count > 0
                acad.Documents(0).Close(False)
            Loop

        acad = Nothing

        FORCIBLY_AUTOCAD_TO_PDF_BY_ONE_BY_LAYOUTS = "Пакетная печать на отдельные листы - завершена!"


    End Function

Now I found the solution 🙂 I replace errored fragment on to:

 

                acad.ActiveDocument.SendCommand("_-layout" & vbCr & "_set" & vbCr & LayP(1) & vbCr)

                acad.ActiveDocument.SendCommand("_-plot" & vbCr & "_N" & vbCr & LayP(1) & vbCr & "" & vbCr & "DWG_To_PDF_Gallurgy.pc3" & vbCr & _
                                                Me.PDF_Dir & "\" & LayP(1) & ".pdf" & vbCr & "_N" & vbCr & "_Y" & vbCr)

It's work!

 

I'm trying to print invisible! But I didn't get: print window is still open! That is enough for a while.

 

0 Likes
Message 4 of 5

Alfred.NESWADBA
Consultant
Consultant
Accepted solution

Hi,

 

for your first issue you might try to change the line to that syntax:

      acad.ActiveDocument.Plot.SetLayoutsToPlot(CObj(LrsToPlot))   ' <---- ERROR, Because it's OBJECT

 

I would avoid to use .SendCommand as much as possible because you don't get a feedback when something went wrong in the commandline.

So you can also change the sysvar setting to something like that:

      acad.ActiveDocument.SetVariable("FILEDIA", 0)
      acad.ActiveDocument.SetVariable("CMDDIA", 0)

 

>> I'm trying to print invisible! But I didn't get: print window is still open!

The systemvariable for printing in background is BACKGROUNDPLOT, you can play with activating it. But you should know that your code then will not wait the end of the plot and continues to run, that often ends in some strange results, so change that only if you really need it and only if your code is really safe.

 

HTH, - alfred -

 

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 5 of 5

Anonymous
Not applicable

Alfred, thank you for your help! 🙂

0 Likes