Subscribe to this thread
Home - General / All posts - Assign and Change Projection for multiple components in manifold 8
samuelgj13 post(s)
#02-Apr-16 00:17

Hello,

Can someone sendme a script to assign (verify projections) for multiple components at once, and for change projections for multiple components as well for Manifold 8.0?

Please! I have hundreds of components!

tjhb

7,545 post(s)
#02-Apr-16 00:44

Try a forum search. 1 2 3.

The 3rd link has the newest code.

samuelgj13 post(s)
#03-Apr-16 05:45

Great! It worked just fine! Now I have to change the projection of all to UTM Zone 13 North America Mexico and Central America. Do you have the script for this?

<preset>

<name>Universal Transverse Mercator - Zone 13 (N)</name>

<datum>North American 1983 (Mexico, Central America)</datum>

<system>Transverse Mercator</system>

<unit>Meter</unit>

<majorAxis>6.378137000000000000000000e+006</majorAxis>

<eccentricity>8.181919104281579200000000e-002</eccentricity>

<centerX>0.000000000000000000000000e+000</centerX>

<centerY>0.000000000000000000000000e+000</centerY>

<centerZ>0.000000000000000000000000e+000</centerZ>

<rotationX>0.000000000000000000000000e+000</rotationX>

<rotationY>0.000000000000000000000000e+000</rotationY>

<rotationZ>0.000000000000000000000000e+000</rotationZ>

<scaleAdjustment>0.000000000000000000000000e+000</scaleAdjustment>

<scaleX>9.996000000000000400000000e-001</scaleX>

<localScaleX>1.000000000000000000000000e+000</localScaleX>

<scaleY>9.996000000000000400000000e-001</scaleY>

<localScaleY>1.000000000000000000000000e+000</localScaleY>

<falseEasting>5.000000000000000000000000e+005</falseEasting>

<localOffsetX>0.000000000000000000000000e+000</localOffsetX>

<falseNorthing>0.000000000000000000000000e+000</falseNorthing>

<localOffsetY>0.000000000000000000000000e+000</localOffsetY>

<centerLat>0.000000000000000000000000e+000</centerLat>

<centerLon>-1.050000000000000000000000e+002</centerLon>

Attachments:
Projection UTM Zone 13 North America.xml

tjhb

7,545 post(s)
#03-Apr-16 06:59

You might be able to do that yourself. For each drawing, use its .Project method. (Again a forum search might help.) Otherwise yes, code tomorrow.

tjhb

7,545 post(s)
#03-Apr-16 07:40

Sorry, I meant .ProjectTo.

You pass it an argument created with Application.NewCoordinateSystem using the exact name of a built-in projection, using its default datum, or if you need to use XML to override this use .NewCoordinateSystemFrom instead.

samuelgj13 post(s)
#04-Apr-16 02:34

Thankyou very much!

samuelgj13 post(s)
#04-Apr-16 03:15

It would be great if you sendme the script for change projections as well

I am not a programmer.

tjhb

7,545 post(s)
#04-Apr-16 06:03

Of course that's fine--neither am I.

But giving it a try might lead on to other things, if you want it to.

tjhb

7,545 post(s)
#05-Apr-16 02:56

Here you go.

This script changes the projection of all target components to exactly match the projection of one source component of the same type. (Drawing to drawings, for example, or surface to surfaces.)

To use it:

  • Confirm the projections of all target components, either with Assign Projection or a script
  • Give the source component the exact projection you want to apply to target components, using Assign Projection and Change Projection as necessary
  • If you want to reproject all components of the same type in the project, put the source component in the project root
  • If you only want to reproject components within a folder, put the source component in the target folder
  • Select that source component in the Project pane
  • Run the script

' Change the coordinate system of components*

' of the same type** and in the same folder***

' as the currently selected component

' to match its exact projection****

' * provided their current coordinate system has been verified

' ** Drawing, Image, Surface, Theme or Labels

' *** or in the whole project, if the selected component is in the root

' **** including custom local offsets and scales (if any)

'

Option Explicit

Sub Main

    Dim app ' Application

    Dim comps ' ComponentSet

    Dim source ' Component

    Dim targetCS ' CoordinateSystem

    Dim folder ' Component

    Dim scopeName ' string

    Dim comp ' Component

'

    Set app = Application

'

    ' get source component and target CS

    Set source = SourceComponent

    Set targetCS = Nothing

    If source Is Nothing Then

        app.MessageBox "Select a source Drawing, Image, Surface, Theme or Labels component" & vbCrLf _

            & "in the Project pane before running the script.", _

            "Change projections to match component"

    ElseIf Not IsEmpty(source.Owner) Then

        ' source is a bound component

        ' use the CS of its owner (if verified)

        If source.Owner.CoordinateSystemVerified Then

            Set targetCS = source.Owner.CoordinateSystem

            ' NB only unbound components

            ' of the same type as the source

            ' will be reprojected

        Else

            app.MessageBox "Confirm the projection of [" & source.Owner.Name & "]" & vbCrLf _

                & "before running the script.", _

                "Change projections to match component"

        End If

    Else

        If source.CoordinateSystemVerified Then

            Set targetCS = source.CoordinateSystem

        Else

            app.MessageBox "Confirm the projection of [" & source.Name & "]" & vbCrLf _

                & "before running the script.", _

                "Change projections to match component"

        End If

    End If

'

    If Not targetCS Is Nothing Then

        ' set target scope

        If IsEmpty(source.Folder) Then

            ' source is in root

            Set comps = Document.ComponentSet

            scopeName = "the current project"

        Else

            Set comps = source.Folder.Children

            scopeName = "[" & source.Folder.Name & "]"

        End If

        ' confirm and apply

        If Application.MessageBoxEx("Change the coordinate system of all " & source.TypeName & " components" & vbCrLf _

                & "in " & scopeName & " to match [" & source.Name & "]:" & vbCrLf & vbCrLf _

                & vbTab & targetCS.Preset & vbCrLf & vbTab & targetCS.Datum.Name & vbCrLf & vbTab & TargetCS.Unit.Name & vbCrLf & vbCrLf _

                & "A component will only be reprojected if its current" & vbCrLf _

                & "projection has been verified.", _

                "Change projection to match selection", _

                MessageBoxTypeOKCancel) = MessageBoxResultOK Then

            For Each comp in comps

                If comp.ID = source.ID Then ' source object

                    'app.History.Log vbTab & "skip [" & comp.Name & "]: source component" & vbCrLf

                ElseIf comp.Type = ComponentFolder Then

                    'app.History.Log vbTab & "skip [" & comp.Name & "]" & vbCrLf

                ElseIf comp.Type <> source.Type Then

                    'app.History.Log vbTab & "skip [" & comp.Name & "]: different type" & vbCrLf

                ElseIf Not IsEmpty(comp.Owner) Then

                    ' dependent components do not have their own CS,

                    ' must be reprojected via their owner

                    app.History.Log vbTab & "skip [" & comp.Name & "]: dependent component" & vbCrLf

                ElseIf Not comp.CoordinateSystemVerified Then

                    app.History.Log vbTab & "skip [" & comp.Name & "]: coordinate system not verified" & vbCrLf

                Else

                    ' matching component type with verified CS

                    If comp.CoordinateSystem.IsEqualTo(targetCS, TrueTrueThen

                        app.History.Log vbTab & "skip [" & comp.Name & "]: already matching source" & vbCrLf

                    Else

                        ' change projection

                        comp.ProjectTo targetCS

                        app.History.Log vbTab & "[" & comp.Name & "] -> " & targetCS.Preset & vbCrLf

                    End If

                End If

            Next ' comp

        End If

    End If

End Sub

'

Private Function SourceComponent 

    ' Return the vector or raster component

    ' (Drawing, Image, Surface, Theme, Labels)

    ' selected in the Project pane

    ' (otherwise Nothing)

    Dim comps

    Dim comp

    Dim name

    Set comps = Document.ComponentSet

    Set comp = Nothing

    If comps.Count > 0 Then

        name = Application.UserInterface.Panes("Project").ControlSet("TreeViewComponents").Text 

        If name <> "" Then 

            Select Case Document.ComponentSet(name).Type

                Case ComponentDrawing, ComponentImage, ComponentSurface, ComponentTheme, ComponentLabels

                    Set comp = Document.ComponentSet(name)

                'Case Map

                    ' Change Projection paradigm does not apply to maps

                    ' Use Assign Projection script

                Case Else

            End Select

        End If

    End If

    Set SourceComponent = comp

End Function

Attachments:
Change projections to match component.txt

samuelgj13 post(s)
#05-Apr-16 22:47

Thanks Pal! You are the best!

This really made my day it was too much wor to do this one by one!

tjhb

7,545 post(s)
#05-Apr-16 22:59

I'm glad it was useful.

It's not very pretty—but part of this is that I built on some old code, and for that reason wrote in VBScript.

That was a mistake! Now that I'm used to (Iron)Python, I find VBScript a truly horrible language. I feel as if I can't do anything elegantly or efficiently.

On the other hand, you can do simple, elegant and powerful (and sometimes brainy) all at once in Python.

If you do take some steps in the direction of learning a language for scripting Manifold, pick the one you personally like best, obviously, but I strongly recommend (Iron)Python, even though it's a slight pain to set up in Manifold 8. On which see here, in interested.

I'll probably rewrite the above in IronPython soon.

cassini89 post(s)
#29-Jan-17 13:34

Hello,

I try to use this script that seems to meet my expectations, but having no script bases, I have a little trouble using it.

My scope: change all images folder projection in once. By following the indications, the script asks me every time to choose a source ... Can you clarify a little more the indications tjhb give .. by thanking you

R.A

cassini89 post(s)
#29-Jan-17 19:09

Hello again,

I attach a file, on this subject of change of projection to a batch of images,

Thank you for your indulgence

Attachments:
script.map

tjhb

7,545 post(s)
#05-Feb-17 00:23

Sorry for not replying sooner.

This script may not be ideal for your purpose, but it will work if you follow the instructions.

There were some minor errors above.

Corrected and clarified:

  • Confirm the projections of all target components, either with Assign Projection or a script

[There is a script to confirm the projection of many components at once here--link corrected to later script version.]

  • Give the source component the exact projection you want to apply to target components, using Assign Projection and Change Projection as necessary
  • If you want to reproject all components of the same type in the project, put the source component in the project root
  • If you only want to reproject components within a folder, put the source component in the target folder
  • Open the script in its own window
  • Select the source component in the Project pane
  • In the script window, press Run

Manifold User Community Use Agreement Copyright (C) 2007-2017 Manifold Software Limited. All rights reserved.