Target all selected Illustrator objects, or target all objects if none are selected - adobe-illustrator

How can I target an Adobe Illustrator script to limit itself to the user's selection if anything is selected, or to run on all objects if nothing is selected?
app.activeDocument.selection is often used to target the current selection but is empty if there's no selection.

app.activeDocument.pageItems is where to access all items as if everything was selected. So, this one liner:
var scope = app.activeDocument.selection.length ? app.activeDocument.selection : app.activeDocument.pageItems;
...sets the variable scope to be the selection if there is one, or everything if there is none. Its contents can then be cycled through the normal way, for example:
for(var i=0;i<scope.length;i++){
// do things with scope[i]
}

Related

How do I save selected objects as a variable and recall that selection in PowerPoint using VBA?

I am trying to build a macro that allows the user to select a few ojbects in PowerPoint, name that selection, then at a later stage pick a name to reselect those objects.
I am stuck at saving the current selection as a variable, and saving that variable as part of the PPT, so that when a user opens the file again those selections are still availible.
I've tried declaring a variable of the Selection type, and setting its value to the active selection. But this gives an error.
You can't save a selection as such, but you can tag the selected shapes when the user opts to save the current selection, then when the user chooses to re-select that particular selection, look at each shape on the slide and if it has the appropriate tag, add it to the selection.
I have a free add-in that does pretty much what you're after:
https://pptools.com/free/FAQ00003-Selection-Manager.htm

PowerPoint VBA add shape event/ add shape with tag value

i'am currently trying to add a small function to PowerPoint using VBA, my goal is to create a gadget that works kind of like Photoshop graphics layer.
My plan is to add a layer name Tag on each shape that is drawn by user, so later I can parse through every item by loop and preform lock/unlock, show/hide shapes based on it's tag value, such as:
Sub add_shape_with_layer_tag()
Set islide = ActivePresentation.Slides(1)
Set ishape = islide.Shapes.AddShape(msoShapeRectangle, 5, 5, 80, 60)
ishape.Tags.Add "Layer", "1"
End Sub
Sub show_hide_layer_one_shapes()
Dim active_slide As Slide
Set active_slide = ActiveWindow.View.Slide
For Each ishape In active_slide.Shapes
If ishape.Tags("Layer") = "1" Then
ishape.Visible = Not (ishape.Visible)
End If
Next ishape
End Sub
However, I couldn't found a way to achieve this, so I would like to ask whether there's a method that provides following functions?
override add shape function so I can sneak tag value in to shape every time user drawn a shape
catch add shape event (if this thing did exist) so i can add tag to the last added item
a way to set a default tag value to shape, just like setting default shape color/line width
or is there any better options that is also viable?
thanks.
20200728
To John, thanks for the advice, I did found some interesting event that might be helpful for some of my other projects, however I couldn't found events that able to trigger after custom function while shape is added.
To Steve, my plan is to add a modeless userform with list UI that manage layers, the shape tag and shape fill texture/color will be determined based on what list item that currently selected.
As to saving settings, I'll use VBComponents.CodeModule to dump existing settings in userforms to a VBA module and store as text, so in theory I should able to make this function self contained in one file.
Not totally an answer, sorry SO, but comments don't allow enough scope for this. So ...
To Steve, my plan is to add a modeless userform with list UI that manage layers, the shape tag and shape fill texture/color will be determined based on what list item that currently selected.
Ah, so you're creating your own "pseudo-layers". That wasn't clear. Thanks for the add'l info. As it happens, I have a selection manager add-in that works very similarly to what you're proposing.
To John, thanks for the advice, I did found some interesting event that might be helpful for some of my other projects, however I couldn't found events that able to trigger after custom function while shape is added.
The SelectionChange event should get you there. When it fires, you'll need to check first to see if the current selection is a shape or something else. If a shape, check to see if its .Index = current slide's .Shapes.Count and also to see if you've already tagged it. If no tag AND if it's the correct index, it'll be a newly added shape. If you're tagging ALL shapes, you may only need to check to see if the .Tag(name) is blank.
As to saving settings, I'll use VBComponents.CodeModule to dump existing settings in userforms to a VBA module and store as text, so in theory I should able to make this function self contained in one file.
Why not save any needed slide or presentation level info as further slide- or presentation-level tags? PPT can absorb quite a lot of info as tags w/o getting cranky.

Excel VBA mulitiple checkboxes

is it possible to create listbox with multiple checkboxes in one row (Excel VBA)?
Thanks
Kamil
I'm not sure I understood your question fully, but I'll elaborate on ListBoxes as much as I can.
First things first: Checkboxes and ListBoxes are different objects in Excel Userforms. The first is the little box that returns a "true/false". The second is a list of items which can be chosen. Clicking in a Checkbox will make the tick mark appear/disappear (or fade if tristate is enabled), while clicking a Listbox row will turn the listbox row "blue"/"white" (or whatever color is being used for the selected rows). In both elements, clicking is a way to toggle between True and False.
While a checkbox only allows for a single information to be marked as True or False, a Listbox allows you to select entries out of a list. That list may be inserted through code (.AddItem method) or passed from a range (.RowSource property)
ListBox objects allow for multiple columns of data to be attributed to one row element, but each row is an entire element (which means you cannot pick the element on row 3, column 2 - only all of row 3). The number of columns is established using the ColumnCount property.
By changing the value of the MultiSelect property, you'll allow the user to select multiple or single row elements simultaneously on your Listbox. Using the Selected( RowIndex ) property, you can check whether or not an item is currently selected (returns True/False). Remember that row indexes start at 0.
Finally, if you're using the MultiSelect property set to fmMultiSelectSingle and have a single column (as far as I know), the Text property can be used to return the selected item's value.
An easy example of a listbox is in Excel can be found at File > Options > Customize Ribbon (or something like that). There are two listboxes, one (on the left) with the visible items and another with the available items. A pair of command buttons is used to move items between boxes. That's a simple application you can likely find already setup online.
Am I on track to answer your question?

Setting shape position to book layout in vba

I want to use a word macro to set the position of the shapes in the document to book layout (see screenshot). But I can't find any reference which member I need to set for this (probably because my word is in german and this is called differently in the macro).
Can anyone tell me how to set the horizontal layout of a shape to book layout in vba?
[update] The following did the trick:
Shape.Left = -999994
Shape.LeftRelative = -999999
Shape.RelativeHorizontalPosition = wdRelativeHorizontalPositionMargin
In the most recent versions of Word the macro recorder gives no help for graphical objects. The next best thing you can do is to look at the properties available for the object in the Object Browser (F2).
If a graphical object has "text wrap" formatting then it belongs to the Shapes collection, so the list you need to look up is that of the Shape object.
In there you'll find the property RelativeHorizontalPosition, which takes a member of the WdRelativeHorizontalPosition enumeration. Looking at that list there are a number of options, none of which has "book" in it.
So the next step is to insert and format a Shape with the desired positioning. Then in the Immediate Window (Ctrl+G) you can type:
?ActiveDocument.Shapes(1).RelativeHorizontalPosition
Then press Enter. This will print a number that corresponds to the list of Enumeration members.
You can also test the effect of the various members by assigning them in the Immediate Window:
ActiveDocument.Shapes(1).RelativeHorizontalPosition = wdRelativeHorizontalPositionOuterMarginArea
Press Enter.
What you'll see is that there is not an enumeration member for every option in the dialog box. And that various positioning options in the dialog box correspond to a single enumeration member.
For your specific question, wdRelativeHorizontalPositionInnerMarginArea corresponds to the dialog box option you indicate.
ActiveDocument.Shapes(1).RelativeHorizontalPosition = wdRelativeHorizontalPositionInnerMarginArea
Besides the above, you need to use the LeftRelative and Left properties, as well. Take a look at those settings in the Immediate Window after using the dialog box and play with them, putting the image on odd/even pages.If it disappears - it's off visible portion of the page, which you can see in Reading View. In a nutshell, you need the NEGATIVE numbers to lock the image to the margin or page side. Positive numbers position it absolutely.

Cell in Devexpress Treelist is set to editable yet it won't let me edit

I am using a DevExpress (10.2) Treelist in my VB.Net project in Visual Studio 2008. I currently have a treelist with TreeList.OptionsBehavior.Editable = True. I have two columns were the first one is AllowEdit = False. The second column I am setting the AllowEdit and ReadOnly dynamically though the action FocusedNodeChanged.
Within the FocusedNodeChange subroutine I check if a specific value is in the row and if so I set it to be editable or non-editable. I am setting it to be editable with:
treeList.Columns("field_name").OptionsColumn.ReadOnly = False
treeList.Columns("field_name").OptionsColumn.AllowEdit = True
and setting it to readonly with:
treeList.Columns("field_name").OptionsColumn.ReadOnly = True
treeList.Columns("field_name").OptionsColumn.AllowEdit = False
This works to a degree. Right now if I go in the editable cell in the treelist the cursor appears and blinks so I know it is editable and if I go in the cell when the un-editable row is focused the cursor doesn't blink.
However even though the cursor blinks I am unable to type. When I click on keys (numbers and letters) on the keyboard nothing is written.
SOLVED
Simple solution. The stored procedure I was using to fetch the data into the table didn't contain the field for the particular column I was trying to make editable and not editable. This was because it was a new value that was insert/updated differently than normal. To fix this I fetched null and/or 0 and it worked fine.
The code you are using is not quite correct. The best solution is to handle the TreeList's ShowingEditor event and set the e.Cancel parameter accordingly. To determine the current cell, use the TreeList's FocusedColumn and FocusedNode properties.