TurboCAD Forums

The Ultimate Resource for TurboCAD Knowledge

Register
 
Be sure your post is relevant to the current discussion.  Create a new topic within the appropriate board if you are unsure.

Open turbocad, select by query, and pan to selection
Read 2341 times
* February 03, 2015, 01:15:34 AM
Hi people,
I had this posted in the Contributions section - and then realised I am not contributing but asking (!) so have moved thread and edited.
I am wanting to open Turbocad from an Access Database, find a string, and then pan to the string.

So far I have success with opening TCAD with the correct drawing, but  I am having no joy in creating code to select by query and then panning. If I want to pan to a graphic, I don't necessarily need to select it.

I am using Access 2010 and TCAD deluxe 19.2
My search string is defined as [searchcon]

Code: [Select]
Private Sub Command353_Click()


Dim TCApp
Dim TCDraw
Dim TCGraphics
Dim TCGroupGraphic
Dim TCSel
Dim TempGraphic
Dim myStr
Dim TCGraphic
Dim g As Long
Dim TCWselectbyquery



On Error Resume Next
myStr = "path to my file in here"

Set TCApp = CreateObject("TurboCAD.Application")
TCApp.Visible = True
Set TCDraw = TCApp.Drawings.Open(myStr)

End Sub


Any pointers appreciated
thanks

Logged


* February 05, 2015, 11:29:39 AM
#1
Hi matty
I found an old macro
it was running in TC15 with vba

it selects in an open drawing, and pan the view to the selection. No change of zoom
==========
Sub pan2queryselection()
Dim grs As GraphicSet

Dim actview As View
Dim xcenview As Double
Dim ycenview As Double

Dim xcenworld As Double
Dim ycenworld As Double

Dim xworld As Double
Dim yworld As Double
Dim x1view, y1view   As Double
Dim xleft As Double
Dim ytop As Double

Set grs = ActiveDrawing.Graphics.QuerySet("PenColor = 255")  'QuerySelect = red graphics
grs.Select

Set actview = ActiveDrawing.ActiveView                        ' pan the view
 xcenview = actview.ViewLeft + 0.5 * actview.ViewWidth
    ycenview = actview.ViewTop - 0.5 * actview.ViewHeight
    actview.ViewToWorld xcenview, ycenview, 0, xcenworld, ycenworld, 0
    dx = x1 - xcenworld: dy = y1 - ycenworld
    actview.WorldToView xcenworld + dx, ycenworld + dy, 0, xleft, ytop, 0

    actview.ViewLeft = xleft - 0.5 * actview.ViewWidth: actview.ViewTop = ytop + 0.5 * actview.ViewHeight: actview.Refresh
    ActiveDrawing.Views.Refresh

Set grs = Nothing
ActiveDrawing.Selection.Unselect
End Sub

« Last Edit: February 05, 2015, 11:32:26 AM by ibruethsch »

Logged


* February 06, 2015, 12:42:52 AM
#2
Thanks very much for digging this out, and replying.
I have had a go. I had to define a few more variables to parse the script, but still no response (although my drawing is opening), and nothing is getting selected/deselcted. Here is the slightly modified script:

Code: [Select]
Sub Command355_click()
Dim TCTools
Dim tcapp
Dim TCDraw
Dim TCGraphics
Dim TCGroupGraphic
Dim TCSel
Dim TempGraphic
Dim myStr
Dim TCGraphic
Dim g As Long
Dim TCWselectbyquery
Dim searchcon As String
searchcon = Me.ContextSearchmem

On Error Resume Next
myStr = "path to file"

Set tcapp = CreateObject("TurboCAD.Application")
tcapp.Visible = True
Set TCDraw = tcapp.Drawings.Open(myStr)

Dim grs As GraphicSet

Dim actview As View
Dim xcenview As Double
Dim ycenview As Double

Dim xcenworld As Double
Dim ycenworld As Double

Dim xworld As Double
Dim yworld As Double
Dim x1view, y1view   As Double
Dim xleft As Double
Dim ytop As Double
Dim x1 As Double
Dim Y1 As Double
Dim dx As Double
Dim dy As Double


Set grs = ActiveDrawing.graphics.QuerySet("PenColor = 255")  'QuerySelect = red graphics
grs.Select

Set actview = ActiveDrawing.ActiveView                        ' pan the view
 xcenview = actview.ViewLeft + 0.5 * actview.ViewWidth
    ycenview = actview.ViewTop - 0.5 * actview.ViewHeight
    actview.ViewToWorld xcenview, ycenview, 0, xcenworld, ycenworld, 0
    dx = x1 - xcenworld: dy = Y1 - ycenworld
    actview.WorldToView xcenworld + dx, ycenworld + dy, 0, xleft, ytop, 0

    actview.ViewLeft = xleft - 0.5 * actview.ViewWidth: actview.ViewTop = ytop + 0.5 * actview.ViewHeight: actview.Refresh
    ActiveDrawing.Views.Refresh

Set grs = Nothing
ActiveDrawing.selection.Unselect
End Sub

Although I am using V19.2 I also have a copy of 21 deluxe installed. Having checked my VB libraries out, I can see that several of the Turbocad ones have installed with TCAD21, and perhaps I have some compatibility issues.

thanks again
Matt

Logged


* February 06, 2015, 10:23:37 AM
#3
Hi Matt
grs.select don't work here with TC20
I use the 32bit-version. Cannot say annything about 64-bit version.

==========
For i = 0 To grs.Count - 1
ActiveDrawing.Selection.Add (grs(i))
Next
=========
works here with TC20-32

regards
Bernd

Logged