News:

All posts discussing pricing or where to buy TurboCAD will be deleted.

Main Menu

Viewport Properties

Started by Colin Edgar, June 01, 2024, 05:26:42 PM

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

Colin Edgar

Does anyone know how to access a paperspace viewport's properties (specifically the viewport's camera settings in my case) using the SDK? I'm using VBA within Excel 2013. I can get the settings of the modelspace default camera using IMSIGX.Application.ActiveDrawing.ActiveView.Camera, but I can't figure out how to get (or set) a viewport's camera settings. I haven't found any info in the SDK documentation. Any ideas are appreciated.
Thanks
TurboCAD Deluxe 2021 (64-bit, ver. 28, build 50); Windows 11 Home; Lenovo Legion 7, Intel Core Ultra 9 275HX, 2.70GHz, 24 cores, 32GB RAM, NVIDIA GeForce RTX 5070

nikkipollard

#1
Hi Colin.
I am not sure which properties you want to change.
A viewport is a type of Graphic
With special properties.
When you are working with a Graphic Objects properties you need to know the exact name of the property you want to change.
I ran through a list of viewport properties. (And saved them to a text file for you.)
Some of the properties are irrelevant.
And some that you need might not be in the list. - haven't figured out why that happens.

To change a graphic objects properties

gViewport.Properties.Item("PropertyXXX").Value = NewValue

To access a Properties Value

CurrentValue = gViewport.Properties.Item("PropertyXXX").Value

Properties can have different variable types including Arrays, so I added the code for the type of value to the property list.
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

Colin Edgar

Thank you very much, Nikki. This is very helful information. I wouldn't have thought to look under graphic objects. For my education, where did you find all of the property names and their associated variable type?
TurboCAD Deluxe 2021 (64-bit, ver. 28, build 50); Windows 11 Home; Lenovo Legion 7, Intel Core Ultra 9 275HX, 2.70GHz, 24 cores, 32GB RAM, NVIDIA GeForce RTX 5070

nikkipollard

I have an excel file, where I make notes of SDK when I work with it.
It has a few macros in it.
I use this macro a lot.

-You will need to change the sheet number.

Function TCCONNECT() As Boolean
'check Turbocad connection

Dim TCApp As IMSIGX.Application
Dim TCdraw As IMSIGX.Drawing
 
  On Error GoTo oops
   
  Set TCApp = IMSIGX.Application
   
   TCApp.Visible = True
        If TCApp.Drawings.Count > 0 Then
            Set TCdraw = TCApp.ActiveDrawing
        Else
            Set TCdraw = TCApp.Drawings.Add("")
        End If
 
   TCCONNECT = True
 
 
  Exit Function

oops:
   
    MsgBox "Can't Connect to TurboCad try closing and reopening this worksheet"
    TCCONNECT = False

End Function



Sub getproperty()
'get selected graphics properties
If TCCONNECT = False Then

Exit Sub

End If


Sheet20.Visible = True
Sheet20.Activate
Range("B1:F600").Clear

Dim rng As Range
Set rng = Range("B1")
Dim TCApp As IMSIGX.Application
Dim TCdraw As IMSIGX.Drawing
Set TCApp = IMSIGX.Application
Set TCdraw = TCApp.ActiveDrawing
Dim sel As IMSIGX.Selection
Set sel = TCdraw.Selection
If sel.Count > 0 Then

Dim gfx As IMSIGX.Graphic
Set gfx = sel(0)
Dim props As IMSIGX.Properties
Set props = gfx.Properties
Dim prop As IMSIGX.Property
Dim Row As Integer
Row = 3
rng.Cells(1, 1).Value = "Type"
  rng.Cells(1, 2).Value = gfx.Type
  Dim t
  t = gfx.TypeByValue
  rng.Cells(2, 1).Value = "TypeByValue"
  rng.Cells(2, 2).Value = t


Dim i As Integer
i = 0
On Error Resume Next
'I presume if there is an error with the
'Value of the property that the value doesn't apply to that graphic
'or the property is a collection
'some properties get left off the list

For i = 0 To props.Count - 1
    Set prop = props(i)
    rng.Cells(Row, 1).Value = prop.Name
    rng.Cells(Row, 2).Value = prop.Value
    rng.Cells(Row, 3).Value = VarType(prop)

    Row = Row + 1
i = i + 1
Next


Else
    MsgBox "no graphic selected"
End If
 
    Set TCApp = Nothing
    Set TCdraw = Nothing
    Set gfx = Nothing
    Set sel = Nothing



End Sub
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

Colin Edgar

Thank you for sharing this, Nikki. I remember reading something about this in the SDK documentation but didn't quite understand it. Makes a lot more sense now after seeing your getproperty macro. Thanks again for all your help.
TurboCAD Deluxe 2021 (64-bit, ver. 28, build 50); Windows 11 Home; Lenovo Legion 7, Intel Core Ultra 9 275HX, 2.70GHz, 24 cores, 32GB RAM, NVIDIA GeForce RTX 5070

Colin Edgar

Hi Nikki,

Quote from: nikkipollard on June 02, 2024, 12:07:34 AMSome of the properties are irrelevant.
And some that you need might not be in the list. - haven't figured out why that happens.

Just fyi, I did some experimenting with the properties macro and, for whatever reason, I can get more properties to list when I declare variables for the properties. Below is the code that I'm using. I've only used it on a few different graphic types so far so the Select Case statement will likely need to be expanded to prevent other property types from throwing errors and not getting listed. I just have the output go to the Immediate window in VBA.

Option Explicit
Dim TcApp As IMSIGX.Application
Dim TcDwg As IMSIGX.Drawing
Dim TcSel As IMSIGX.Selection
Dim TcGrf As IMSIGX.Graphic
Dim TcGrfProps As IMSIGX.Properties
Dim TcGrfProp As IMSIGX.Property
Dim TcGrfName, TcGrfType, TcGrfPropName As String
Dim TcGrfPrnt, TcGrfLay, TcGrfPropVal As Variant
Dim TcGrfId, TcGrfTypeVal, TcGrfPropIndx, TcGrfPropType, TcGrfPropsCount As Long

'Subroutine to show the extended properties for the selected graphic
'Description of the values returned for the graphic's Type property (same as VBA VarType):
'0  = empty
'1  = null
'2  = integer
'3  = long integer
'4  = single-precision floating-point number
'5  = double-precision floating-point number
'6  = currency value
'7  = date value
'8  = string
'9  = object
'10 = error value
'11 = boolean value
'12 = variant (used only with arrays of variants)
'13 = data access object
'14 = decimal value
'17 = byte value
'20 = longlong integer (valid on 64-bit platforms only)
'36 = variants that contain user-defined types
'8192 + Num = array of type Num (e.g., 8192 + 12 = 8204 = array of variants)
Sub GetGrfProp()

    On Error GoTo ErrorTrap
    Set TcApp = IMSIGX.Application
    Set TcDwg = TcApp.ActiveDrawing
    Set TcSel = TcDwg.Selection
    If TcSel.Count > 0 Then
        Set TcGrf = TcSel(0)
        Set TcGrfProps = TcGrf.Properties
        TcGrfName = TcGrf.Name
        TcGrfPrnt = TcGrf.Parent
        TcGrfId = TcGrf.ID
        TcGrfType = TcGrf.Type
        TcGrfTypeVal = TcGrf.TypeByValue
        TcGrfLay = TcGrf.Layer.Name
        TcGrfPropsCount = TcGrfProps.Count
        Debug.Print "Name: " & TcGrfName
        Debug.Print "Parent: " & TcGrfPrnt
        Debug.Print "ID: " & TcGrfId
        Debug.Print "Type: " & TcGrfType
        Debug.Print "Type value: " & TcGrfTypeVal
        Debug.Print "Layer: " & TcGrfLay
        Debug.Print "Number of extended properties: " & TcGrfPropsCount
        Debug.Print "Index, Name, Type, Value"
        On Error Resume Next
        For Each TcGrfProp In TcGrfProps
            TcGrfPropIndx = TcGrfProp.Index
            TcGrfPropName = TcGrfProp.Name
            TcGrfPropType = TcGrfProp.Type
            TcGrfPropVal = TcGrfProp.Value
            Select Case TcGrfPropType
                Case 8204: Debug.Print TcGrfPropIndx & ", " & TcGrfPropName & ", " & TcGrfPropType & ", [array]"
                Case Else: Debug.Print TcGrfPropIndx & ", " & TcGrfPropName & ", " & TcGrfPropType & ", " & TcGrfPropVal
            End Select
        Next
        On Error GoTo 0
    Else
        MsgBox "No graphic selected."
    End If
    Set TcGrfProps = Nothing
    Set TcGrf = Nothing
    Set TcSel = Nothing
    Set TcDwg = Nothing
    Set TcApp = Nothing
    Exit Sub

ErrorTrap:
    MsgBox "Error #" & Err.Number & ": " & Err.Description

End Sub
TurboCAD Deluxe 2021 (64-bit, ver. 28, build 50); Windows 11 Home; Lenovo Legion 7, Intel Core Ultra 9 275HX, 2.70GHz, 24 cores, 32GB RAM, NVIDIA GeForce RTX 5070

nikkipollard

As easy as that? Thank you Colin
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h