MikeShepard / VisioBot3000

Simple Visio Automation from Powershell
MIT License
50 stars 13 forks source link

New-VisioShape Enhancement Request - Connect the new shape to an existing shape using it's connection point formula. #77

Open mc1903 opened 3 years ago

mc1903 commented 3 years ago

Hi Mike,

In the example attached, I notice that when I manually move/connect the Server1 shape onto the Rack01 shape, that Server1's 1-D endpoints are changed to a formula referencing the Rack01 connection points. Would it be possible to change New-VisioShape to allow a formula to be specified for each of x & y, so it is connected to the existing shape on creation?

The shapes are from http://www.visiocafe.com/hpe.htm (HPE-Racks.vss is in HPE-Common.zip and HPE-ProLiant-DL.vss is in HPE-ProLiant.zip)

VisioBot3000_New-VisioShape.pdf

Thanks M

MikeShepard commented 3 years ago

@mc1903 - what would you suggest as the syntax for this?

mc1903 commented 3 years ago

Hello @MikeShepard

As this would only pertain to rack & server shapes, I would suggest something like:

New-VisioShape -Master HPEDL180Gen108SFF -Label Server1 -Rack Rack01 -FirstU 1

Where -Rack is the label of the existing rack shape and where -FirstU is the first/lowest U space to connect the new shape.

Some validation of the rack shape to would be ideal to confirm the U connection points are correctly labelled in the ShapeSheet as the HPE racks are, but the Dell ones are blank.

VisioBot3000_New-VisioShape_RackConnectionLabels.pdf

When specifying the -Rack and -FirstU parameters, the -x and -y parameters would not be required.

Thanks, M

MikeShepard commented 3 years ago

Adding rack-specific parameters to New-VisioShape is a very different thing than adding the ability to allow formulas for -x and -y parameters.

mc1903 commented 3 years ago

Hello Mike,

"Adding rack-specific parameters to New-VisioShape is a very different..." Yes, without a doubt it is far more involved. Apologies, I misunderstood your initial question about syntax.

From what I now understand (which is limited) New-VisioShape is using the VBA Master.Drop method, which can only accept floating-point numbers.

I am trying to work out which VBA method to call in order to update a shape's 1-D endpoints - do you happen to know what this might be?

Thanks, M

mc1903 commented 3 years ago

I have a dirty working example now... I will try to create a new function New-VisioRackShape that takes the -Rack and -FirstU parameters.

New-VisioDocument
Set-VisioPage -Name 'Page-1'

Register-VisioStencil HPE-Racks -Path 'D:\Users\mc1903\Documents\My Shapes\HPE\HPE-Racks.vss'
Register-VisioStencil HPE-ProLiant-DL -Path 'D:\Users\mc1903\Documents\My Shapes\HPE\HPE-ProLiant-DL.vss'

Register-VisioShape -Name HPE42U600Rack -StencilName HPE-Racks -MasterName 'HPE 42U G2 Adv Rack Front'
Register-VisioShape -Name HPEDL180Gen108SFF -StencilName HPE-ProLiant-DL -MasterName 'DL180 Gen10 8LFF front'

New-VisioShape -Master HPE42U600Rack -Label Rack01 -x 1 -y 3
New-VisioShape -Master HPEDL180Gen108SFF -Label Server1 -x 5 -y 1

$p=Get-VisioPage
$Master = $Server1
$Label = $Master.Name
$NewRackShape=$p.Shapes | Where-Object {$_.Name -eq $Label}

$NewRackShape.Cells("BeginX").FormulaU = "PAR(PNT(Rack01!Connections.U01B.X,Rack01!Connections.U01B.Y))"
$NewRackShape.Cells("BeginY").FormulaU = "PAR(PNT(Rack01!Connections.U01B.X,Rack01!Connections.U01B.Y))"
$NewRackShape.Cells("EndX").FormulaU = "PAR(PNT(Rack01!Connections.U01E.X,Rack01!Connections.U01E.Y))"
$NewRackShape.Cells("EndY").FormulaU = "PAR(PNT(Rack01!Connections.U01E.X,Rack01!Connections.U01E.Y))"

M

MikeShepard commented 3 years ago

I could see a version of New-VisioShape which had -XFormula and -YFormula ....would that work? Would it have to be -BeginXFormula, etc. (4 parameters)?

mc1903 commented 3 years ago

Morning Mike,

So I don't break the current New-VisioShape code (which I need for testing), I will look to get it working as a separate New-VisioRackShape function first.

Personally, I wouldn't use -XFormula and -YFormula. I'd prefer to specify -Rack (probably actually -RackLabel now) along with -FirstU and let the code work out the 1-D endpoint formulas for me.

Looking at various vendor's rack shapes (HPE, Dell, IBM, Cisco), the formulas are slightly different. As far as I have found, irrespective of vendor BeginX & BeginY are the same formula, as are EndX & EndY. A 3rd parameter -RackVendor will allow the code to create the correctly formatted formulas.

I appreciate the downside to this approach is that the function will need to be updated for additional rack shapes if they have different 1-D endpoint formulas. Are there any other rack vendor shapes you use / would want to support?

M

mc1903 commented 3 years ago

Hi Mike,

I have zip attached the updated VisioShape.ps1 file that includes the New-VisioRackShape function for review.

You can test it with the following:

#Create New Visio Session and Blank 'Page-1'
New-VisioDocument

#Register HPE Stencils
Register-VisioStencil HPE-Racks -Path 'D:\Users\mc1903\Documents\My Shapes\HPE\HPE-Racks.vss'
Register-VisioStencil HPE-ProLiant-DL -Path 'D:\Users\mc1903\Documents\My Shapes\HPE\HPE-ProLiant-DL.vss'

#Register HPE Shapes
Register-VisioShape -Name HPE42U600EntRackF -StencilName HPE-Racks -MasterName 'HPE 42U G2 Ent Rack Front'
Register-VisioShape -Name HPEDL180Gen108LFF -StencilName HPE-ProLiant-DL -MasterName 'DL180 Gen10 8LFF front'
Register-VisioShape -Name HPEDL580Gen10SFF -StencilName HPE-ProLiant-DL -MasterName 'DL580 Gen10 front'
Register-VisioShape -Name HPEDL360Gen108SFF -StencilName HPE-ProLiant-DL -MasterName 'DL360 Gen10 8SFF front'

#Drop New Rack Shape
New-VisioShape -Master HPE42U600EntRackF -Label Rack01 -x 1 -y 3

#Drop New Rack Equipment Shapes into the Existing Rack Shape
New-VisioRackShape -Master HPEDL180Gen108LFF -Label Server1 -RackLabel Rack01 -RackVendor HPE -FirstU 1
New-VisioRackShape -Master HPEDL580Gen10SFF -Label Server2 -RackLabel Rack01 -RackVendor HPE -FirstU 3
New-VisioRackShape -Master HPEDL580Gen10SFF -Label Server3 -RackLabel Rack01 -RackVendor HPE -FirstU 7
New-VisioRackShape -Master HPEDL360Gen108SFF -Label Server4 -RackLabel Rack01 -RackVendor HPE -FirstU 11
New-VisioRackShape -Master HPEDL360Gen108SFF -Label Server5 -RackLabel Rack01 -RackVendor HPE -FirstU 12

Let me know what you think. I can create a pull request if you want me to.

M

VisioBot3000_New-VisioRackShape.zip

MikeShepard commented 3 years ago

I'm glad you were able to get that working. I'm hesitant to add it to VisioBot3000 directly, because it's so shape-specific. What would you think about getting it added in the examples folder (probably with some instructions on downloading rack stencils)?

mc1903 commented 3 years ago

Morning Mike,

I understand your hesitance about adding it to VisioBot3000 directly. I would be happy to work on examples & instructions, but how best to make the New-VisioRackShape function (along with some others I am thinking about) easily available?

Would you be agreeable to me creating a separate VisioBot3000AddOns or VisioBot3000Extras repo along with its own PowerShell Gallery install package? No replication of the existing VisioBot3000 functions, just a place to keep dependant custom functions that is apart from your main project.

Cheers, M

MikeShepard commented 3 years ago

Sorry about the slow response. I've thought some more about it and here are my conclusions:

  1. I appreciate the idea of having "adjunct" modules to extend VisioBot. That would be an ok solution.
  2. I have reconsidered including this function in the main module. If it brings more people to use VisioBot, then that's great.

So...if you will put together a pull request for the function (make sure to include comment-based help) and an example or 2 showing how to use it (a short example in the CBH would be awesome...an extended one in the Examples folder would be great too), I'll review and we'll see about getting it merged.

If you'd like, I can still update the New-VisioShape function to allow formulas for x and y. That might simplify the New-RackShape function some.

mc1903 commented 3 years ago

No worries Mike; we all have real lives to live.

I tried moving the New-VisioRackShape function out into it's own module, but ran into issues as some of the variables/arrays ($Shapes and poss $DroppedShape) are no longer available, I assume they are restricted to the script: scope of the New-VisioShape or the Register-VisioShape function.

New-VisioRackShape -Master HPEDL180Gen108LFF -Label Server1 -RackLabel Rack01 -RackVendor HPE -FirstU 1 -Verbose

Cannot index into a null array.
At C:\Program Files\WindowsPowerShell\Modules\VisioBot3000Extras\Src\Public\New-VisioRackShape.ps1:111 char:13
+             $Master=$script:Shapes[$Master]
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

I have an exam this Friday, so I am prepping for that at the moment. Towards the end of next week I have some time off, so I will create a PR once I have sorted the CBH and examples.

I think updating New-VisioShape to accept formulas for x and y would be great.

M

MikeShepard commented 3 years ago

I'll try to get that updated (formulas) so you can use it as a springboard for your PR.

On Wed, Sep 22, 2021 at 11:22 AM mc1903 @.***> wrote:

No worries Mike; we all have real lives to live.

I tried moving the New-VisioRackShape function out into it's own module, but ran into issues as some of the variables/arrays ($Shapes and poss $DroppedShape) are no longer available, I assume they are restricted to the script: scope of the New-VisioShape or the Register-VisioShape function.

New-VisioRackShape -Master HPEDL180Gen108LFF -Label Server1 -RackLabel Rack01 -RackVendor HPE -FirstU 1 -Verbose

Cannot index into a null array. At C:\Program Files\WindowsPowerShell\Modules\VisioBot3000Extras\Src\Public\New-VisioRackShape.ps1:111 char:13

  • $Master=$script:Shapes[$Master]
  • 
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

I have an exam this Friday, so I am prepping for that at the moment. Towards the end of next week I have some time off, so I will create a PR once I have sorted the CBH and examples.

I think updating New-VisioShape to accept formulas for x and y would be great.

M

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/MikeShepard/VisioBot3000/issues/77#issuecomment-925085425, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABKI2IWVXYWXMLP5DD6WBPTUDH7DPANCNFSM5DF7QEFA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

-- https://powershellstation.com