Automating data in autocad using VBA - vba

I have a drawing file in autocad dwg format which shows trees and their tree number in text. now i want to create a excel file having details of tree number and their coordinates. Till now i have achieved looping through the tree object and then user has to input the tree number. Can this process be automated using the proximity calculation i.e. the code search for nearest text and then attaches the tree number from the text to the tree on excel sheet.

You can use SelectionSet to select texts inside tree. More You can see for example here.
https://www.engram9.info/autocad-2006-vba/selecting-entities.html
It would be something like:
Dim p1 As Variant
Dim p2 As Variant
tree.GetBoundingBox p1, p2
Set objSS = ThisDrawing.SelectionSets.Add("TestSelectSS")
objSS.Select acSelectionSetWindow, p1 , p2
Be carefull please. It's just writen by hand, I don't even know if it will run, but just want to point You direction.
Then You need to iterate through objSS , and get text You want. You may also use SelectionSet filters, so objSS.Select will return only texts.

Related

CATIA VBA: Extract name of generated point in CATDrawing

I'm tearing my hair out trying to work with generatedpoints in draft view. I have a 3D model with points that are named in a particular way, per the picture below:
point names
Then on the CATDrawing, I have generated views that show those points. if I click those points in 2D, they are named in the following manner, "GeneratedPoint (insert 3D point name here)". You can see this naming example below:
2D generated naming
Now, what I'm trying to do in VBA is run a code that will select those generated points in a view, duplicate geometry on them, and name that duplicated geometry to match the 3D point names. My problem is, I can't seem to access the "GeneratedPoint" names that show up when I click the points in 2D. Below is a snippet of my code where I'm trying to access the name of the selected points:
For j = 1 To totalcnt
Set bSel = aDoc.Selection
bSel.Add ActiveView
bSel.Search "Name='*GeneratedPoint *',sel"
Set nm = bSel.Item(j)
desc = nm.Name
desc = nm.Value.Name
Usually when I have a selection, and I make an object from one of those selections, I can access the name through selection.Item(j).Name or selection.Item(j).Value.Name, but in this case neither one works.
at the desc=nm.Name line above, it gives me a name of "CATIASelectedElement16", not the actual name I see in the status bar when I click it in the drawing. And when I use desc=nm.Value.Name it gives me "Front View", which is the name of the view these points are in. I know it's selecting the points correctly, I can see them get selected, and I can see the count on the selection object matches my number of points. What am I missing? For reference, when I run the line Set nm=bSel.Item(i), that object looks like this in the Locals window.
Object in Locals window
As you can see in that picture, the object Type is DrawingView, whereas I would expect it to be a point. Does anyone have any ideas on how to access the name of a generated item in 2D? So far the only way I can interact with it at all is by using selection.Search, which will find them by name, but I have no way of then actually using the specific names of those points it found. Any insight would be appreciated!

VBA: How to avoid a date format change when Pasting an Excel Chart

I have created 5 graphs and tables that are uploaded to an Email thanks to this Question Pasting an Excel range into an email as a picture
Unfortunately, my first graph has a change in the date's format when pasted in Excel already, whereas the second one (and all others) still look exactly similar to what I created.
What other way are there to copy paste graphs or what should I look at to make sure this doesn t happen?.
First Graph with date as number
Sheets(2).ChartObjects(1).Chart.CopyPicture
Dim p2 As Picture
Set p2 = ActiveSheet.Pictures.Paste
'here date format changed
Sheets(3).ChartObjects(1).Chart.CopyPicture
Dim p3 As Picture
Set p3 = ActiveSheet.Pictures.Paste
'here no change
I finally found an answer from another website:
"The date format problem happens because the axis formats are probably
linked to the source data. As long as the source data is in an open
workbook, Excel will go and find the format and apply it. To get around
this, before copying the chart, double click on the axis, select the
Number tab, and uncheck the Link to Source checkbox."
Jon Peltier

MS Word Ignores Content Control Inside a Rich Text Box

Is there a reason why my MS Word VBA macro is ignoring a dropdown list I placed inside a shape (a rich text box)? I've tried referring to it by tag, name, number, etc. I even had the macro tell me the count of content controls:
MsgBox(ActiveDocument.ContentControls.Count)
I get 0.
Nothing works. If I take it out of the shape, it works fine. MS Word gives me a count of 1 item. But for some reason MS Word won't acknowledge it inside the shape. Any help on how to do this?
Edited as my previous post was completely wrong.
Each textbox in the main text story is a Shape which you can access using an index number. A shape has various properties but text etc. is in its Textframe, if it has one. But in that case the Range you need is not called Range but TextRange. So, e.g. the first contentControl in Shape 2 is
ActiveDocument.Shapes(2).TextFrame.TextRange.ContentControls(1)
You will probably need to iterate through your shapes and you may need to verify that a given shape is a textbox and/or that it has a TextFrame.
If your text box is in another Story such as a header or footer, you will probably need to identify the relevant StoryRange.

VBA Word : SmartArts and range

I'm currently working with SmartArts in Word.
The SmartArt already exists, and I would like to find a way to access a SmartArt value from a range, Office cursor (so Selection) or something akin to it.
Here's my SmartArt.
To be exact, the SmartArtLayout is Application.SmartArtLayouts(88)
What I can do already :
Create a SmartArt on my Document, keep it as a Shape to work on it.
Looping on all the Nodes of my SmartArt, selecting the ones I want to keep, and inserting the ones I want to keep in a database, with a link to their parent.
Now I'm blocked on something.
I want to find a Way to edit/delete a particular node, both in DB and in the SmartArt.
It would be possible if I made a Userform that put every Shape Text in a drop-down list, and I then looped on all shapes to find the shape with the chosen text in it.
If noone answers, that'll probably be what I am going to do.
But I don't find this way natural or practical.
So I'm looking for a method to be able to find the Node that have the cursor on it. I would've done something like that :
'Putting my SmartArt in SAShape
For Each Node In SAShape.SmartArt.AllNodes
If (Selection.Range.InRange(Node.Range)) Then
'my code
End If
Next Node
But It'd have been too easy... The shapes don't seem to have a range.
Is there a way to get the Node with focus, or to get the node we clicked on?
Thanks in advance!
Cordially,
firt It not like Question but it is task but i will give you some hint to help you
1) to get any node in any level loop will be like this
Set oShape = ActiveSheet.Shapes(1)
For i = 1 To oShape.SmartArt.AllNodes.Count
oShape.SmartArt.AllNodes(i).TextFrame2.TextRange.Text = "Sample " & i
Next
2)To Get specific node for delete or edit you must determine an id i can not do that perfect but i assign the id to alt text when i add alt text i can find any node
2.1) when shearch
nod.TextFrame2.TextRange.Text = str
nod.Shapes(1).AlternativeText = index
2.2) when check for search
If oShape.SmartArt.AllNodes(i).Shapes(1).AlternativeText = index
and the imge will show where alt store
that i think will help you in some way for do what you need but you must understand how smart art tree change after item delete
smartart

VBA Macro 'Moving" Graphics / Dynamic Graphs

Basically, the problem here is that I have a macro which changes the number of a specific cell and by doing that I change the numbers from three columns and when those numbers are changed my graphic starts to 'move'.
To be more specific, I have this graphic:
When I click on the button I have, the lines starts to move, and it looks like a mouth opening and closing.
The blue line corresponds to the first and second column values, whereas the red line is changed accordingly to the first and third column values:
Cell(B2) contains the number generated by this code:
Sub OpenMouth()
For i = 1 To 20
Worksheets("Mouth").Cells(2, 2).Value = 0.1 + 2 * i / 20
Calculate
For j = 1 To 5000000
Next j
Next i
End Sub
What I need to do is to prepare something similar: A graphic that by changing the numbers I have in columns A, B and C, it starts to move. The columns A, B and C will be changed by doing a simple loop in VBA, this loop will change one value, and the three columns will have a formula linked to this value, so they will have their values changed.
I've seen some really cool graphics, a ball rolling, a wheel moving, but I really don't have a clue of how to do this, I don't know how to do it.
Does anyone have an idea? Can anyone help me build a different graphic with a similar idea (of an object moving)?
This is another example, using the same logic:
Frankly, I would suggest rethinking your approach of creating a custom & complex animation in Excel. Excel just isn't the right tool for this.
I would use Javascript and embed a Internet Explorer control into Excel with the animation. The solution would work as follows:
Press a button in Excel
A VBA macro executes the animation by loading the Microsoft Web Browser control with a custom HTML file with your animation in Javascript. The animation is show in the MS Web Browser Control.
Drawing in Javascript
Here a simple tutorial:
http://www.w3schools.com/html/html5_canvas.asp
Test your drawings here:
http://www.codecademy.com/courses/web-beginner-en-SWM11/0/1
Microsoft Web Browser Control
https://msdn.microsoft.com/en-us/library/aa752040(v=vs.85).aspx